Giter VIP home page Giter VIP logo

js-control-flow-training's Introduction

Control Flow Training

Be mindful of infinite loops, especially common with while. They can crash your browser!

Consider adding a temporary counter variable to limit the maximum number of iterations:

// numIterations ensures this while loop doesn't go on forever
var numIterations = 0;
while (true && numIterations < 100){
  console.log("still going!");
  numIterations++;
}

Security Questions

Work in the security_questions.js file.

  1. Create an array called securityQuestions. Each element of securityQuestions will be an object with two keys: question and expectedAnswer.

  2. Populate (fill) securityQuestions with at least three such objects. Feel free to just make them up. For example, one security question object might be:

    { question: "What was your first pet's name?", expectedAnswer: "FlufferNutter" }
  3. Write code that goes through each of the security questions in your array doing the following:

  • use window.prompt (short name: prompt) to create a popup in the browser with the question
  • check whether the user's input matches the expected answer
    * if the answer does match, ask the next question * if the answer doesn't match, stop asking questions and pop up an alert message.

Login

Work in the login.js file.

  1. Create a userLogin object with one key for a user's name and one key for the user's password. (Just make up a user name and password.)

  2. Write code that prompts the user for their password with a message customized to the user. For example, if the user name you created is octocat_rules, the message should be "Enter password for user octocat_rules."

  3. Extend your previous code to check whether the password entered by the user actually matches the password in the userLogin object. The code should let the user know whether the passwords matched with console logs or a JavaScript alert.

  4. If the passwords don't match, prompt the user to enter their password again. If the passwords match, make sure your code doesn't prompt the user again.

Bonus: Modify your user login to give the user only three chances to enter the correct password.

Sing!

Work in the sing.js file.

  1. Write code that console logs the "Bottles of beer on the wall" song:

     5 bottles of beer on the wall,
     5 bottles of beer!
     Take one down and pass it around,
     4 bottles of beer on the wall!
    
  2. Bonus: fix "1 bottles of beer". It should say "1 bottle of beer".

  3. Bonus: change "0 bottles..." to "No more bottles...".

  4. Bonus: Use a JavaScript prompt to ask the user how many verses they want to hear.

js-control-flow-training's People

Contributors

bgveenstra avatar justincastilla 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.