Forum Discussion
JamesGregg
8 hours agoCommunity Member
Need help checking my JavaScript
Hi all -
I'm creating an interactive micro-learning where the users will answer 3 questions on each of 4 slides (total of 12 questions). Each of the 4 slides presents a different human interactio...
- 7 hours ago
Look at section 2, you never defined retail, collxns, traffic, or cust, you defined retail1, retail2, retail3, etc. Also your template only outputs 4 boxes, not 12. Even after the ReferenceError is fixed, the HTML only references one variable per scenario, so you’d lose 8 of the 12 answers.
JamesGregg
7 hours agoCommunity Member
Thank you! As you have likely deduced, I am a bit of a JS newbie (well, I did it about 25 years ago when I was hardcoding webpages from scratch, but....the brain fade is real ;)) I appreciate your helpful and prompt reply!
DShaw
7 hours agoCommunity Member
Also worth noting with your code; a stray < or & in someone’s notes might mangle the output. If it were me I’d escape the input. Something like this:
function esc(s){
return String(s)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/\r\n|\r|\n/g, "<br>");
}