JavaScript Syntax for IF...ELSE inside of contents—dynamic choices
May 17, 2018
By
Jeff Dunn
Hey all - hoping someone could help me here! I am less than a novice at JavaScript and I have some existing code (attached) where I am trying to print out some variables that I collect during a module that I created. However, the trick is that I only want to display them IF they have been populated...
So for example, for the line:
contents+="<div style='font-size:17px;margin-top:5px;'>"+q1+"</div>";
I don't want anything to show if q1 has never been populated with any info.
In essence, I have the learner clicking on a series of boxes. They have 34 to choose from, but I need something to print out that shows which ones they clicked, without showing all the ones they DIDN'T click. Anyone?
1 Reply
Wrap these two lines:
contents+="<div style='font-size:18px;font-weight:bold;margin-top:10px;’>Question 1</div>";
contents+="<div style='font-size:17px;margin-top:5px;'>"+q1+"</div>";
inside an if tq1 <> "" statement, and the same for the other pairs.
I'd have to check w3schools.com (or a similar resource) for the exact syntax, but that's the principle.
This discussion is closed. You can start a new discussion or contact Articulate Support.