Multiple Identical Options in Switch Statements / Not Working

Multiple Identical Options in Switch Statements / Not Working
0

#1

Tell us what’s happening:

Your code so far

  var answer = "";
  // Only change code below this line
  
  switch (val) {
    case 1:
    case 2:
    case 3:
      answer = "Low";
      break;
    case 4:
    case 5:
    case 6:
      answer = "Mid";
      break;
    case 7:
    case 8:
    case 9:
      answer = "High";
      break;
  }
  
  
  // Only change code above this line  
  return answer;  
}

// Change this value to test
myTest(1);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:


#2

Do you have a question?


#3

anyone please find the bug in the above code ?


#4

Hi,
Maybe just a copy / paste error but you seem to have lost your first line of the function.
function myTest(val){


#6
function myTest(val) {
  var answer = "";
  // Only change code below this line
  
  switch (val) {
    case 1:
    case 2:
    case 3:
      answer = "Low";
      break;
    case 4:
    case 5:
    case 6:
      answer = "Mid";
      break;
    case 7:
    case 8:
    case 9:
      answer = "High";
      break;
  }
  
  
  // Only change code above this line  
  return answer;  
}

// Change this value to test
myTest(1);


#7

Till now not working.


#8

But it is working now?

I’m fairly sure that should work. If it is failing the challenge it might be because you renamed the function to myTest. If you change the name then the test software will not work properly even if your function is valid.


#9

Thanks bro :slight_smile: ,Finally it works