How to do Comparison two number with the switch statement

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function isLess(a, b) {
// Only change code below this line
switch(a, b){
  case (a < b):
  return true;
  default:
  return false;
}
// Only change code above this line
}

isLess(10, 15);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36.

Challenge: Returning Boolean Values from Functions

Link to the challenge:

What exactly is your question? A swtch is not designed to be used like this. A switch matches a single expression against multiple cases.

1 Like

thank you! but can you give me one solution to resolve this problem??

We don’t give out solutions. I can help you fix your code though.

The first step would be removing the switch statement all together.

1 Like
function isLess(a, b) {

  if (a < b) {

    return true;

  } else {

    return false;

  }

}

isLess(10, 15);

the function is like this but i want to change this code to use a switch statement

Why do you want to use a switch? This is the wrong type of thing to do with a switch statement.

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

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