Skip to content

Latest commit

 

History

History
36 lines (23 loc) · 1.04 KB

if-statement.md

File metadata and controls

36 lines (23 loc) · 1.04 KB

Conditional statements are used to alter the control flow of a program, based on a specified boolean condition.

A conditional statement looks like this:

if (n > 1) {
  console.log('the variable n is greater than 1.');
} else {
  console.log('the variable n is less than or equal to 1.');
}

Inside parentheses you must enter a logic statement, meaning that the result of the statement is either true or false.

The else block is optional and contains the code that will be executed if the statement is false.

The challenge:

Create a file named if-statement.js.

In that file, declare a variable named fruit.

Make the fruit variable reference the value orange with the type of String.

Then use console.log() to print "The fruit name has more than five characters." if the length of the value of fruit is greater than five. Otherwise, print "The fruit name has five characters or less."

Check to see if your program is correct by running this command:

javascripting verify if-statement.js

Index