Java switch statements

Java switch statements
0.0 0

#1

Hi everyone,

Can anyone help me with this?

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (answer) {
    case 1:
      consol.log("alpha");
      break;
    case 2:
      console.log("beta");
      break;
    case 3:
      console.log("gamma");
      break;
    case 4:
      console.log("delta");
      break;
    default:
      console.log("default");
      break;
     }
  
  
  // Only change code above this line  
  return answer;  
}

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

It’s from the selecting from many options with Switch Statements challenge, number 190. The guide is the same as the tutorial and when I researched on the internet, it shows exactly how I have written the code but mine is not passing?

Cheers
Mike.


#2

Hi, @M124L.
You don’t need to use consol.log("alpha");
Try to replace it with return "alpha";

Good luck!


#3

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

You’re also using the wrong variable in switch. What goes in switch(..) is the variable that you want to test the value of.


#4

It’s called JavaScript. You can’t abbreviate it to Java. Java is a different language.


#5

Thank you for your help


#6

Thank you for the information, I will remember that in the future.


#7

Thank you for the link, I always wondered how to do that :slight_smile:


#8

You’re welcome. It’s unfortunate that they share these 4 letters. Just wanted to help avoid confusion.