So basically I need to make my site turn from one image to another using JavaScript and variables after a question is answered. I will prompt the user about there mood from 1-10 an dif they pick 1-3(sad) the image changes to a sad face if they pick 4-7(neutral) the image changes to a neutral face if they pick 8-10(happy) the image on the site will change to a happy face. my code though is not working I've tried everything
<head>
<title>Mood</title>
<meta charset="UTF-8">
<script>
var sad = 1 , sad2 = 2, sad3 = 3;
var n1 = 4, n2 = 5, n3 = 6, n4 = 7;
var h1 = 8, h2 = 9, h3 = 10;
var x = prompt("What is your mood from 1-10? 1 being sad, 10 being Happy.","What is your mood?");
if(x === sad || x === sad2 || x === sad3){
document.getElementByTagName("img").src = "sad.png";
document.getElementById("msg").innerHTML = "Sad.";
document.getElementById("msg").href = "http://www.sad.com";
}
else if(x === n1 || x === n2 || x === n3 || x === n4){
document.getElementByTagName("img").src = "neutral.png";
document.getElementById("msg").innerHTML = "Neutral.";
document.getElementById("msg").href = "http://www.neutral.com";
}
else if(x === h1 || x === h2 || x === h3){
document.getElementByTagName("img").src = "happy.png";
document.getElementById("msg").innerHTML = "Happy.";
document.getElementById("msg").href = "http://www.happy.com";
}
</script>
</head>
<body style="text-align:center">
<img src="neutral.png">
<h1><a id="msg" href="">Waiting...</a></h1>
</body>
It gives me no errors in my coding I'm using NetBeans but any number I put in the prompt the page just comes out blank.
Waiting...
– NarinderRSharma Jan 30 '16 at 01:32