Rock Paper Scissors Problem Can you help?


#1

function myGame(){

if (‘rock’+‘paper’){

console.log ("Paper wins!");

} else

if ('rock' + 'scissors') {

console.log ("Rock wins!");

} else

if ('paper' + 'scissors') {

console.log ("Scissors wins!")

}
}

myGame (‘paper’ + ‘scissors’)


#2

Is your function meant to take parameters, and if so, how many?


#3

The function needs to have two parameters, I guess?
The code below still always prints “paper wins”

function myGame(a, b){

if (‘rock’+‘paper’){

console.log ("Paper wins!");

} else

if ('rock' + 'scissors') {

console.log ("Rock wins!");

} else

if ('paper' + 'scissors') {

console.log ("Scissors wins!")

}
}


#4

Makes perfect sense.

will always be true. Why? Because 'rock' + 'paper' becomes 'rockpaper' and as a string with some length greater than zero, is truthy, so always true.

if (a === 'rock' && b === 'paper) {
    console.log('b wins');
}