+ 1

Whats wrong with this code?

<script> var rigged=prompt("How old are you?"); var dummy=prompt("What month were you born in?"); var trick=prompt("Are you a boy or a girl?"); var fake=prompt("What is your fa orite color?") var real=prompt("What grade are you in?") if(real >= 8){ alert("You are cool!") } else { alert("You are not cool") } </script>

31st Aug 2017, 11:15 PM
Noah
7 Réponses
+ 2
/* Nest your code in a function and call the function in window.onload */ function mainFunc(){ var rigged=prompt("How old are you?"); var dummy=prompt("What month were you born in?"); var trick=prompt("Are you a boy or a girl?"); var fake=prompt("What is your faorite color?") var real=prompt("What grade are you in?") if(real >= 8){ alert("You are cool!") } else { alert("You are not cool") } } window.onload = function(){ mainFunc() }
31st Aug 2017, 11:30 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 1
Oh yeah (;) could be it I thought too much 😂
31st Aug 2017, 11:27 PM
Khaledjall_37
Khaledjall_37 - avatar
+ 1
Yeah probably learned it the hard way 😂😂
31st Aug 2017, 11:29 PM
Khaledjall_37
Khaledjall_37 - avatar
+ 1
<script> var rigged=prompt("How old are you?"); var dummy=prompt("What month were you born in?"); var trick=prompt("Are you a boy or a girl?"); var fake=prompt("What is your fa orite color?"); var real=prompt("What grade are you in?"); if(real >= 8){ alert("You are cool!"); }; else { alert("You are not cool"); } </script> What about now
31st Aug 2017, 11:35 PM
Noah
0
Btw it's supposed to be rigged
31st Aug 2017, 11:15 PM
Noah
0
I'm not an expert but maybe the prompt is returning a string and you need an integer? Try googling how to convert string to integer in javascript.
31st Aug 2017, 11:22 PM
Khaledjall_37
Khaledjall_37 - avatar
0
Thanks! @Nomeh Uchenna Gabriel That fixes it now.
31st Aug 2017, 11:44 PM
Noah