After the user has entered in an appropriate choice, I need to use a conditional statement that compares the input to my choices, and then render an image on the web page. I know somehow I have to use the CSS display, and possibly a if/then statement but I'm not entirely sure how or where. So far, I have this in my javascript. I'm not sure what I should use so that if the user inputs 'red' that a picture would appear (it's going to be Hogwarts related). Any tips in the right direction?
function myFunction() {
var text;
var favColor = prompt("What color appeals most to you out of red, green, blue, or yellow?", "Let the game begin");
switch(favColor.toLowerCase()) {
case "blue":
text = "Sounds like you like to think";
break;
case "red":
text = "Feeling bold?";
break;
case "green":
text = "Really? Interesting choice";
break;
case "yellow":
text = "How very clever of you!"
break;
default:
text = "C'mon! Pick one!";
}
document.getElementById("demo").innerHTML = text;
}
Aucun commentaire:
Enregistrer un commentaire