Code Monkey home page Code Monkey logo

conditional_test2's Introduction

Exercise Link:

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Test_your_skills:_Conditionals

Instructions:

For this task you are given three variables:

  • machineActive - contains an indicator of whether the answer machine is switched on or not
    (true/false)
  • score — Contains your score in an imaginary game. This score is fed into the answer machine, which provides a response to indicate how well you did.
  • response — begins uninitialized, but is later used to store a response that will be printed to the output panel.

You need to create an if...else structure that checks whether the machine is switched on and puts a message into the response variable if it isn't, telling the user to switch the machine on.

Inside the first if...else, you need to nest another if...else that puts appropriate messages into the response variable depending on what the value of score is — if the machine is turned on. The different conditional tests (and resulting responses) are as follows:

  • Score of less than 0 or more than 100 — "This is not possible, an error has occurred."
  • Score of 0 to 19 — "That was a terrible score — total fail!"
  • Score of 20 to 39 — "You know some things, but it's a pretty bad score. Needs improvement."
  • Score of 40 to 69 — "You did a passable job, not bad!"
  • Score of 70 to 89 — "That's a great score, you really know your stuff."
  • Score of 90 to 100 — "What an amazing score! Did you cheat? Are you for real?"

My Solution:

let response;
    let score = 90;
    let machineActive = false;

    // Add your code here
    if (machineActive) {
      if (score < 0 || score > 100) {
        response = "This is not possible, an error has occurred.";
      } else if (score >= 0 && score <= 19) {
        response = "That was a terrible score — total fail!";
      } else if (score >= 20 && score <= 39) {
        response =
          "You know some things, but it's a pretty bad score. Needs improvement.";
      } else if (score >= 40 && score <= 69) {
        response = "You did a passable job, not bad!";
      } else if (score >= 70 && score <= 89) {
        response = "That's a great score, you really know your stuff.";
      } else if (score >= 90 && score <= 100) {
        response = "What an amazing score! Did you cheat? Are you for real?";
      }
    } else {
      response = "Please turn on the machine to see score";
      score = "loading...";
    }

conditional_test2's People

Contributors

vickyluvs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.