26.2 Who won the match | Sololearn: Learn to code for FREE!

0

26.2 Who won the match

I've written the following function to determine which team wins the match depending on the score. However the console is telling me that my else if statement is incorrect on line 4... Can anyone help? function finalResult(goalsTeam1, goalsTeam2) if (goalsTeam1 > goalsTeam2) { return "Team 1 won"; } else if (goalsTeam1 < goalsTeam2) { return "Team 2 won" } else{ return "Draw" } //complete the function function finalResult() {

3/21/2021 9:39:53 AM

Gee Henry

2 Answers

New Answer

0

Two semicolons (line 5 and 7) and brackets {} for the fuction are missing. use proper codion style to identify syntax errors easier

0

semi colon are optional in non "strict mode" (even if it's better practice to put them explicitly, as they are inserted automatically for you, wich could produce unexpected behavior hard to debug)... however you are mandatory to open curly bracket after function arguments list, and close bracket at end of function body... conversely, you could avoid curly brackets enclosing if/else body if there's only one statement inside (even if some consider that too much error prone and less readable): function finalResult(goalsTeam1, goalsTeam2) { if (goalsTeam1 > goalsTeam2) return "Team 1 won"; else if (goalsTeam1 < goalsTeam2) return "Team 2 won"; else return "Draw"; } last line must be removed as was rest of the provided code template wich you have rewrite above (missing the opening curly bracket)