JS 26.2 Practice Multiple Parameters -- need help | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3

JS 26.2 Practice Multiple Parameters -- need help

Hey guys, I can't figure out what's wrong with this bit of code. I'm not sure if i'm even doing this right, because I didn't use parameters? Problem: You are given a program that takes Team 1 and Team 2 football teams goals as inputs accordingly. Complete the function to take Team 1 and Team 2 goals as arguments and output the final result of the match: - "Team 1 won", if Team 1's score is higher than Team 2's score - "Team 2 won", if Team 2's score is higher than Team 1's score - "Draw", if the scores are equal Sample Input 3 4 Sample Output Team 2 won Here's what I tried: function main() { var goalsTeam1 = parseInt(readLine(), 10); var goalsTeam2 = parseInt(readLine(), 10); // function call finalResult(goalsTeam1, goalsTeam2) } //complete the function function finalResult() { if(goalsTeam1>goalsTeam2){ document.write("Team 1 Won") } else if(goalsTeam2>goalsTeam1){ document.write("Team 2 Won") }else{ document.write("Draw") } };

25th Jan 2022, 11:38 PM
Nate Raia
11 Antworten
+ 9
function finalResult(goalsTeam1,goalsTeam2) { var goalsTeam1 = parseInt(readLine(), 10); var goalsTeam2 = parseInt(readLine(), 10); if ( goalsTeam1 > goalsTeam2 ) { console.log("Team 1 won") } else if ( goalsTeam2 > goalsTeam1 ) { console.log("Team 2 won") } else { console.log("Draw") } }; finalResult();
28th May 2022, 3:10 PM
Chris O. Wilkie
Chris O. Wilkie - avatar
+ 4
function main() { var goalsTeam1 = parseInt(readLine(), 10); var goalsTeam2 = parseInt(readLine(), 10); // function call finalResult(goalsTeam1, goalsTeam2) var team1; var team2; } //complete the function function finalResult(team1 , team2) { if (team1 > team2 ){ console.log("Team 1 won"); } else if(team1 < team2){ console.log("Team 2 won"); } else console.log("Draw"); };
15th Oct 2022, 4:07 PM
Tasmia Ishrat Alam Chadni
+ 1
function main() { let goalsTeam1 = 5; let goalsTeam2 = 5; finalResult(goalsTeam1, goalsTeam2); } function finalResult(gT1, gT2) { if(gT1 > gT2) document.write("Team 1 Won"); else if(gT2 > gT1) document.write("Team 2 Won"); else document.write("Draw"); }; main(); https://code.sololearn.com/Wj8NIpV2zTog Good Luck
26th Jan 2022, 2:07 AM
SoloProg
SoloProg - avatar
+ 1
yes you have missing PARAMETERS. //completing the function should look like this: function finalResult(goalsTeam1,goalsTeam2) { if ( goalsTeam1 > goalsTeam2 ) { console.log("Team 1 won") } else if ( goalsTeam2 > goalsTeam1 ) { console.log("Team 2 won") } else { console.log("Draw") } };
29th Jan 2022, 1:24 PM
Galeva Bagelo
Galeva Bagelo - avatar
+ 1
the right answer is : function finalResult(goalsTeam1,goalsTeam2) { var goalsTeam1 = parseInt(readLine(), 10); var goalsTeam2 = parseInt(readLine(), 10); if ( goalsTeam1 > goalsTeam2 ) { console.log("Team 1 won") } else if ( goalsTeam2 > goalsTeam1 ) { console.log("Team 2 won") } else { console.log("Draw") } }; finalResult();
13th Mar 2023, 1:49 AM
Md Hasan Sikder
Md Hasan Sikder - avatar
0
Yes, surely the problem is the missing parameters - the exercise asks for them explicitly (and are needed for the function to know the score anyway)
26th Jan 2022, 12:29 AM
Emerson Prado
Emerson Prado - avatar
0
function main() { var goalsTeam1 = parseInt(readLine(), 10); var goalsTeam2 = parseInt(readLine(), 10); finalResult(goalsTeam1, goalsTeam2); } function finalResult(goalsTeam1,goalsTeam2) { if ( goalsTeam1 > goalsTeam2 ) { console.log("Team 1 won"); } else if ( goalsTeam2 > goalsTeam1 ){ console.log("Team 2 won"); } else { console.log("Draw") } };
11th Nov 2022, 2:59 PM
Daniela Bulimar
Daniela Bulimar - avatar
0
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(goalsTeam2>goalsTeam1){ console.log( "Team 2 won"); } else{ console.log("Draw"); } };
11th Feb 2024, 4:12 PM
S8ul Yuvraj
S8ul Yuvraj - avatar
- 1
simply do this //completing the function should look like this: function finalResult(goalsTeam1,goalsTeam2) { if ( goalsTeam1 > goalsTeam2 ) { console.log("Team 1 won") } else if ( goalsTeam2 > goalsTeam1 ) { console.log("Team 2 won") } else { console.log("Draw") } };
26th Apr 2022, 5:09 PM
Amit Kumar Mishra
- 1
function finalResult(goalsTeam1, goalsTeam2) { if ( goalsTeam1 > goalsTeam2 ) { console.log("Team 1 won") } else if ( goalsTeam2 > goalsTeam1 ) { console.log("Team 2 won") } else { console.log("Draw") } };
9th Jun 2022, 3:56 AM
Zeei Developer
Zeei Developer - avatar
- 1
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 2 won") } else if(goalsTeam2<goalsTeam1){ console.log("Team 1 won") }else{ console.log("Draw") } };
5th Sep 2022, 6:16 PM
Alexander OKUNRINKOYA