Ruby & JS | if-else statements

Syeda Ismat Farjana
1 min readFeb 26, 2021

Day 1: Solving 8 kyu Codewars kata.

Teams and respective scores are given as two arrays. The challenge is to return the result which team wins or is it a draw! I used an if-else statement for both ruby and js.

Ruby: if-else statement

def uefa_euro_2016(team, scores)team1 = team[0]team2 = team[1]if scores[0] == scores[1]p "At match #{team1} - #{team2}, teams played draw."elsescores[0] > scores[1] ? (p "At match #{team1} - #{team2}, #{team1} won!") : (p "At match #{team1} - #{team2}, #{team2} won!")endend

Js: if else if statement

const uefaEuro2016 = (team, scores) => {let result;if (scores[0] < scores[1]) {result = `At match ${team[0]} - ${team[1]}, ${team[1]} won!`;} else if (scores[0] > scores[1]) {result = `At match ${team[0]} - ${team[1]}, ${team[0]} won!`;} else {result = `At match ${team[0]} - ${team[1]}, teams played draw.`;}return result;};

--

--

Syeda Ismat Farjana

I am a physician, eager to learn Coding and eventually jump into the world of AI so I can work for the future.