Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webdev-js-intro-06 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions js/assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}

Expand Down
42 changes: 41 additions & 1 deletion js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
// Prevent us from attempting to use variables
// that are not declared
"use strict"
"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
}