+ 2
In JavaScript, why does it cause a syntax error?
I want to make a code that accepts multiple if, if else, else statements if users prompt in their age, mood, favorite colors... etc...etc... can you help? (it must also be in alert format) and I hope you enjoyed your Christmas!
5 odpowiedzi
+ 2
We probably need code if you want help...
+ 2
<script>alert("hello, this is my questionnaire ")
alert (prompt (" how old are you? "))
</script>
(note: this is not my answer although it is the code that I need help with)
+ 1
First thing: You forgot semi-colon at end of each line
Else I'm not sure you need what you did: prompt() create a new popup, if you do alert(prompt()), the input of user will be directly display in new popup just after he wrote his age.
To use a prompt, you can use a variable:
var age = prompt("How old are you ?");
And after you can use it in a condition:
(Replace x, y and z by numbers you want)
I'll add another var to "simplify" the code. You aren't forced to use it if you want more custom anwser.
var display = "What you want to display if ";
if(age < x)
{
alert(display + "age is under x");
}
else if(age >= x && age > y)
{
alert(display + "age is between x and y");
}
else if(age >= y && age >= z)
{
alert(display + "age is between y and z");
}
else
{
alert(display + "age is upper than z");
}
You can use more or less conditions if you want.
0
1. semicolon when neeeded, syntax is very important.
2. Its if(condition){
codeblock;
} else if (condition){
codeblock;
} else {
}
0
PLSSS HELP ME WHAT IS THE ANSWER