I am writing a program in JavaScript that tells user if they have won in the competition or not. The conditions are: Girl’s record is 20 seconds, boys’ record is 15 seconds false start is anything less than 0.50 seconds, if a contestant has a false start then they have not won. I have to use the prompt() command to ask if they are competing in the boys’s or girls’, then ask for their score, and reaction time. Write a Boolean expression and create a message with alert()command telling them if they have won or not. When asking which event the user is competing in, acceptable answers are “boys” or “girls” . So far I have this, but I don’t think it is entirely right.
var boysRecord = 15;
var girlsRecord = 20;
var falseStart = 0. 50;
var event = prompt("Are you competing in the boys or girls event?");
if (event == "boys" || "girls");
var score = prompt("What is your score?");
} else {
var event = prompt("Are you competing in the boys or girls event?");
var reactionTime = prompt("What is your reaction time?");
if
(event == "boys"; && score > 15; && reactionTime >= 0.5);
{ alert(" You have won");
} else if {
(event = "girls"; && score > 20; && reactionTime >= 0.5);
{ alert(" You have won");
}
else {
alert(" You have lost");
}
First I recommend you indent your code. It's easier to read and helps you keep track of the brackets.
You have a few errors. You are missing some brackets and have too much semicolons.
Here's the code that should work:
var boysRecord = 15;
var girlsRecord = 20;
var falseStart = 0.50;
var event = prompt("Are you competing in the boys or girls event?");
if (event == "boys" || "girls"){
var score = prompt("What is your score?");
} else {
event = prompt("Are you competing in the boys or girls event?")
}
var reactionTime = prompt("What is your reaction time?");
if(event == "boys" && score > 15 && reactionTime >= 0.5){
alert(" You have won");
} else if(event = "girls" && score > 20 && reactionTime >= 0.5){
alert(" You have won");
} else {
alert(" You have lost");
}