0
Why this code show me error
function main() { var goalsTeam1 = parseInt(readLine(), 10); var goalsTeam2 = parseInt(readLine(), 10); // function call finalResult(goalsTeam1, goalsTeam2) } //complete the function function finalResult(goalsTeam1, goalsTeam2) { if (goalsTeam1 > goalsTeam2){ console.log("Team 1 won") }; else if (goalsTeam1 < goalsTeam2){ console.log("Team 2 won") }; else{ console.log("Draw") }; };
1 Answer
+ 2
you should remove the semi colon after "if" block and "else if" block otherwise it will treat them as seperate statement instead of as a whole (if ,else if and else block).
the error is because else if and else can't begin without previous if .