diff --git a/js/assignment.js b/js/assignment.js index c42aba0..ea7c4ad 100644 --- a/js/assignment.js +++ b/js/assignment.js @@ -5,32 +5,42 @@ const evenOrOddElement = document.getElementById("even-or-odd"); const sumTheNumbersElement = document.getElementById("sum-the-numbers"); const createNumberArrayElement = document.getElementById("create-number-array"); -function evenOrOdd() { - const num = 3; - // Write the logic to decide if the variable "num" is even or odd - // and set the element's value the string "Even" or "Odd" accordingly +function evenOrOdd() { + const num = 3; + let result = ""; + if (num % 2 === 0) { // If loop for odd or even + result = "Even"; + } else { + result = "Odd"; + } + evenOrOddElement.innerText = result; } + function sumTheNumbers() { let sum = 0; - // Write the logic to sum the numbers 1 through 10 - // using a for loop. Check the expected output - // on the assignment page - + for (let i = 1; i <= 10; i++) { //for loop for sum of numbers + sum = sum +i; + } + sumTheNumbersElement.innerText = sum; } - + + function createNumberArray() { - const numberArray = []; - - // Write the logic that loops 10 times and adds the value - // to numberArray each iteration. Check the expected output - // on the assignment page - + let numberArray = []; + let x = 0; + while (x <= 9) { //while loop for array + x++; + numberArray.push(x); + } + createNumberArrayElement.innerText = numberArray; } function render() { - // Call the created functions + evenOrOdd(); + sumTheNumbers(); + createNumberArray(); } diff --git a/js/index.js b/js/index.js index 1d44ba9..1925dc4 100644 --- a/js/index.js +++ b/js/index.js @@ -1,3 +1,43 @@ // Prevent us from attempting to use variables // that are not declared -"use strict" \ No newline at end of file +"use strict" + +let i = 0; +while (i < 5) { //loops while 1 < 5 + console.log(i); //Outputs 0 - 4 + i++; //adds 1 to i each time +} + +let x = 0; +do { //does this as long as the while is true + console.log(x); //outputs 0 - 4 + x++; //adds 1 to x each time +} while (x < 5); //loop continues while this is true, +//loop ends once i = 5 + +i = 0; +while (1 < 5) { + console.log ("Hello"); //Me checking to see when we enter this loop + console.log(i); + i++; + if (i === 4){ + break; //breaks when i = 4 + } +}//Outputs Hello 1 - Hello 3 + +i = 10; +x = 0; +while (i < 20) { + i++; + console.log("Diane");//Showing me that we are inside this loop + if (i === 15) { + continue; + + } + x += i; + console.log(x);//Outputs Diane followed by increments starting at 11 + //increasing by 12 then 13 and so on... + //loop stops when 1 = 20 and n = 140 +} + +