Problame with my little game


#1


```
function getRandomIntInclusive(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min +1)) + min;
}
var ordinateur = getRandomIntInclusive(1, 3)
if (ordinateur ==  1){
    ordinateur = "ROI"
}else if (ordinateur == 2){
    ordinateur = "REINE"
}else{
    ordinateur = "VALET"
}
var utilisateur = prompt("Quel est votre carte ?").toUpperCase();

switch(utilisateur){
    case "ROI":
        if (ordinateur == "ROI"){
            console.log("IL ya Egalitee recommancer");
        }else{
            console.log("Dommage vous avez perdue")
            break
        }
    case "REINE":
        if (ordinateur == "VALET"){
            console.log("Bravo vous avez gagner");
            break
        }else if (ordinateur == "REINE"){
            console.log("IL ya Egalitee recommancer")
        }else{
            console.log("Dommage vous avez perdue")
        
    case "VALET":
        if (ordinateur == "ROI"){
            console.log("Dommage vous avez perdue");
            break;
        }else{
            console.log("Bravo vous avez gagner");
            break;
        }
        
    default:
        
}

the console say SyntaxError: expected expression, got keyword 'case'
ho can help me please
`


#2

you didnt close else statement here

else{
            console.log("Dommage vous avez perdue")

and

Switch Statement
syntax:

switch (expression) {
  case value1:
    //Statements executed when the result of expression matches value1
    [break;]
  case value2:
    //Statements executed when the result of expression matches value2
    [break;]
  ...
  case valueN:
    //Statements executed when the result of expression matches valueN
    [break;]
  default:
    //Statements executed when none of the values match the value of the expression
    [break;]
}

break statement only need before next case.you didnt write switch statement properly.check it here

if you need help post your updated code.


#3

thank you its perfect


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.