top of page

Task 2: Using the logical || operator

  • Writer: satyanarayan behera
    satyanarayan behera
  • Aug 25, 2022
  • 1 min read

Imagine you are coding a video game. Currently, you’re about to code some snippets related to the game over condition.

You need to code a new variable named timeRemaining and set it to 0. You also need to code a new variable named energy and set it to 10.

Next, you should write a piece of code that could be used to determine if the game is over, based on whether either the value of the timeRemaining variable is 0 or the value of the energy variable is 0.

Complete the task using the following steps:

  1. Declare the variable timeRemaining, and assign the value of 0 to it.

  2. Declare the variable energy, and assign the value of 10 to it.

  3. Console log the following parameters: "Game over: ", and timeRemaining == 0 || energy == 0

Note that the expected output in the console should be: "Game over: true".

var timeRemaining =0;

var energy =10;

console.log("Game over:", timeRemaining==0 || energy==0);


Recent Posts

See All
For Loop : Task 1

Write a "for" loop that will perform exactly the same repetitive code as this: console.log(1) console.log(2) console.log(3)...

 
 
 

Comments


  • alt.text.label.LinkedIn

©2022 by Satya

bottom of page