Hey dudes!
Sorry to ask such a simple question but I have a time limit and need to know the answer quickly! My mate suggested a quick post on here!
I am working on a project for college - whilst i'm not studying Javascript I need to add some for functionality of my website. I know a bit to get by but seem to have got this wrong all day! I'll simplify it .....
I know that if I write .......
Code:
var userAnswer = prompt("Are you feeling OK today?");
if (userAnswer === "Yes")
{
document.write("Great - glad to hear it");
}
else
{
document.write("Oh dear! That is a shame!")
}
....... a prompt box appears asking "Are you feeling OK today?" and then if the user answers "Yes" .... one response is written and any other answer produces the second response.
What I need to know is - what if I want to write more than one response? For instance - what if I want there to be 4 different answers to the same question - with 4 different responses?
It makes sense to me to write ....
Code:
var userAnswer = prompt("Are you feeling OK today?");
if (userAnswer === "Yes")
{
document.write("Great - glad to hear it");
}
if (userAnswer === "Not bad")
{
document.write("Sorry to hear you are not feeling your best");
}
if (userAnswer === "so so")
{
document.write("Great - glad to hear it");
}
else
{
document.write("Oh dear! That is a shame!")
}
....... but this obviously does not work! I have hunted around but either am not searching for the right thing or am missing the point!
Can anyone please steer me in the right direction?
The project is obviously much harder than this but I need to get the basics down! Eventually each question will have a set of 4 radio buttons and then the answers to the questions delivered on a page ......
Ta in advance!