Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function footballResults(input) {
- let won = 0;
- let lost = 0;
- let drawn = 0;
- for(let i = 0; i < 3; i++) {
- let game = input[i];
- if (game[0] > game[2]) {
- won++;
- } else if (game[0] < game[2]) {
- lost++;
- } else {
- drawn++;
- }
- }
- console.log(`Team won ${won} games.`);
- console.log(`Team lost ${lost} games.`);
- console.log(`Drawn games: ${drawn}`);
- }
- Fundamentals solution with collection and ternary operator:
- function footballResults(input) {
- let result = {'won' : 0, 'lost' : 0, 'drawn' : 0};
- for(let i = 0; i < 3; i++) {
- let game = input[i];
- game[0] > game[2] ? result['won']++ : game[0] < game[2] ? result['lost']++ : result['drawn']++;
- }
- console.log(`Team won ${result['won']} games.\nTeam lost ${result['lost']} games.\nDrawn games: ${result['drawn']}`);
- }
Add Comment
Please, Sign In to add comment