Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
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
5 changes: 5 additions & 0 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
// Example 1
let a;
console.log(a);
// variable is declared but has no assigned value


// Example 2
function sayHello() {
let message = "Hello";
//return "hello"; instead of assigning a variable
}

let hello = sayHello();
Expand All @@ -26,6 +28,7 @@ console.log(hello);
// Example 3
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
//console.log(`Hello ${'walter'}`); nothing was passed in the function
}

sayHelloToUser();
Expand All @@ -34,3 +37,5 @@ sayHelloToUser();
// Example 4
let arr = [1,2,3];
console.log(arr[3]);
// console.log(arr[2])
// the array runs from index 0 -2
11 changes: 10 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
*/

function evenNumbers(n) {
// TODO
let i = 0;
let numberList = [];
while (numberList.length < n){
if (i % 2 === 0){
numberList.push(i);
}
i++
}
console.log(numberList.toString())
}


evenNumbers(3); // should output 0,2,4
evenNumbers(0); // should output nothing
evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18
9 changes: 8 additions & 1 deletion 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const BIRTHDAYS = [
];

function findFirstJulyBDay(birthdays) {
// TODO
let lengthArr = birthdays.length;
i = 0;
while(i < lengthArr){
if(birthdays[i].includes("July")){
return birthdays[i];
}
i++;
}
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
11 changes: 10 additions & 1 deletion 1-exercises/D-do-while/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
*/

function evenNumbersSum(n) {
// TODO
let sum = 0;
let i = 0;
let num = 0;

do{
sum = sum + num ;
num = num + 2;
i = i + 1;
} while (i < n);
return sum;
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
12 changes: 8 additions & 4 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@


// Change the below code to use a for loop instead of a while loop.
let i = 0;
while(i < 26) {
console.log(String.fromCharCode(97 + i));
i++;
// let i = 0;
// while(i < 26) {
// console.log(String.fromCharCode(97 + i));
// i++;
// }

for (let i = 0; i < 26; i++){
console.log(String.fromCharCode(97 + 1));
}
// The output shouldn't change.
4 changes: 4 additions & 0 deletions 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const AGES = [

// TODO - Write for loop code here


for (let i = 0; i < WRITERS.length; i++) {
console.log(`${WRITERS[i]} is ${AGES[i]} years old` );
}
/*
The output should look something like this:

Expand Down