Introducing Else Statements (comments)

Tell us what’s happening:
Describe your issue in detail here.
They said I should not change the code above or below the specified comments. And I don’t know how to do that

  **Your code so far**

Please post your code.
It is difficult to help you without the code.

1 Like

Oh, Sorry
This is my code

function testElse(val) {

  let result = "";

  // Only change code below this line

  if (val > 5) {

    result = "Bigger than 5";

  }

  if  (val <= 5) {

    result = "5 or Smaller";

  }

  // Only change code above this line

  return result;

}

testElse(4);
1 Like

You are asked to change the code to make the two'if statements into one if-else statement.

In case you don’t know I’ll show you an example. :

if (num > 10) {
  return "Bigger than 10";
} 

if (num < 10) {
  return "10 or Less";
}

In this there are two if statements. So how would you make it into one if-else statement?


if (num > 10) {
  return "Bigger than 10";
} else {
  return "10 or Less";
}

This is the if-else statement.The second if from the if-if statement is changed into an else.

The if-else statement above says, if a certain variable num is bigger than 10 return “Bigger than 10”, else if this condition is false than return “10 or less”.



Hope you will be able to solve your problem with the help of this example

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 (’).

1 Like