Files
Randell Dawson 331cbb88f8 fix(guide): Remove repl.it links from challenge related guide articles (English) (#36204)
* fix: remove repl.it links english

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: add extra line

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>
2019-07-01 08:49:24 -05:00

1.3 KiB

title
title
Introducing Else statements

Introducing Else statements

Problem explanation:

· Combine the if statements into a single if/else statement.

Hint 1

When the first if statement returns false the next piece of code is executed/evaluated (like return, if or else statements).

try to solve the problem now

Hint 2

Sometimes if (condition) statements can be replaced by else {code to execute instead} statements (in essence you are telling your function to do "y" if it can't do "x" instead of specifying "x" several times) .

try to solve the problem now

Spoiler alert!

Solution ahead!

Basic code solution:

function testElse(val) {
  var result = "";
  // Only change code below this line
  
  if (val > 5) {
    result = "Bigger than 5";
  }
  
  else {
    result = "5 or smaller";
  }
  
  // Only change code above this line
  return result;
}

// Change this value to test
testElse(4);

Code explanation

The function first evaluates if the condition val > 5 evaluates to true. If it doesn't, it executes the next statement (else { return "5 or smaller";}).

Resources