when I add break after the return this block does not work. It will only work without the breaks
thank you
console.log(getUserChoice('paper'))
function getComputerChoice() {
let randomNumber=Math.floor(Math.random()*3);
switch(randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
}
switch(randomNumber) {
case 0:
return 'rock';
break;
case 1:
return 'paper';
break;
case 2:
return 'scissors';
break;
}
This is to separate it from others, such as when multiple cases use the same code:
function abc(x) {
switch (x) {
case 0:
return "It is 0";
break;
case 1:
case 2:
return "It is 1 or 2";
break;
case 3:
return "It is 3";
break;
}
}
console.log(abc(0));
console.log(abc(1));
console.log(abc(2));
console.log(abc(3));