This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Simple Guessing Game */ | |
| // Create secretNumber | |
| var secretNumber = 4; | |
| // ask user for guess | |
| var guess = Number(prompt("Guess a number")); | |
| //check guess is right | |
| if (guess=== secretNumber) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // while loops | |
| // Print all numbers between -10 and 19 | |
| var x = -10; | |
| while (x <= 19) { | |
| console.log(x); | |
| x++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Anny-omatic */ | |
| /* | |
| // V1 | |
| while (answer !== "yes" && answer !== "yeah" &&) { | |
| var answer = prompt("Are we there yet?"); | |
| } | |
| alert("Yay, we made it !");*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* For Loops Problem Set */ | |
| console.log("Print all numbers between -10 and 19"); | |
| for (var i = -10; i <= 19; i++) { | |
| console.log(i); | |
| } | |
| console.log("Print all even numbers between 10 and 40"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Code Shool Learn JS */ | |
| // LOOPS | |
| // V1 with while | |
| var trainNumber = 1; | |
| while (trainNumber <= 8) { | |
| console.log("Train #" + trainNumber + " is running."); | |
| trainNumber++; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Morph your previous while loop into a for loop that uses the same variable names. Remember, you’ll still need to declare the starting number of sheep and the number of months to print outside the loop. We’ve given you the starting number of sheep again, as well as the amount of months you’ll need to print out for use in the loop parameters. Here’s a solution for the previous while loop for reference: | |
| var numSheep = 4; | |
| var monthNumber = 1; | |
| var monthsToPrint = 12; | |
| while (monthNumber <= monthsToPrint) { | |
| numSheep = numSheep * 4; | |
| console.log("There will be " + numSheep + " sheep after " + monthNumber + " month(s)!"); | |
| monthNumber++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| These Dam Loops! | |
| The Hoover Dam has 19 generators of multiple types. For simplicity, let’s say that the first 4 of these generators output 62 megawatts, and the other 15 output 124 megawatts. In hooverDam.js, the Dam Rangers have asked you to design a system of two loops that turns each generator on in progression, and prints the new total of megawatts generated. | |
| They’d like the first loop to be a while loop handling the first 4 generators. Then, they’d like the second loop to be a for loop that handles the other 15 generators. Each output line should resemble the following lines, with adjusted values for the currentGen and totalMW: | |
| Generator #1 is on, adding 62 MW, for a total of 62 MW! | |
| Generator #2 is on, adding 62 MW, for a total of 124 MW! | |
| We’ve given you some starting variables to use in your build. | |
| */ | |
| var currentGen = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| A Basic Conditional | |
| In countdown.js, modify the while loop with a conditional that will only allow a number to be printed if it is even. Your results should be the even numbers from 10 to 2 in descending order. Think carefully about how your code might decide if a number is even… | |
| */ | |
| var num = 10; | |
| while (num > 0) { | |
| if (num % 2 === 0){ | |
| console.log(num); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Problem Solving with Conditionals | |
| Back at Death Valley, scientists could see that the Sheep Situation would quickly get out of control. They have decided that, for any month the population climbs above 10000, half of the sheep will be sent away to other regions. | |
| Inside our for loop, insert an if statement that: | |
| Removes half of the sheep population if the number of sheep rises above 10000. | |
| Prints the number of sheep being removed to the console in the following format: | |
| Removing <number> sheep from the population. | |
| Note: To complete the challenge, you only need to insert the if statement. You do not need to create an else statement or change any of the provided code. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Some Dam Complex Conditionals! | |
| The people at the Hoover Dam have called you back, and would like a program that shows what happens when only the even numbered turbines are turned on. And they want it all in just one for loop. | |
| With a set of complex conditional statements inside the loop, construct a way to only turn on even numbered turbines. Remember our power output situation: | |
| Generators 1 through 4 produce 62 MW. | |
| Generators 5 through 19 produce 124 MW. |
OlderNewer