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
17 changes: 7 additions & 10 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,23 @@

// Example 1
let a;
console.log(a);

console.log(a); // a is declared as a variable. But no value has been assigned

// Example 2
function sayHello() {
let message = "Hello";
let message = "Hello"; // This function does not return anything, so definition is not enough.
}

let hello = sayHello();
console.log(hello);

console.log(hello); // Variable defined but function must be defined too.

// Example 3
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
console.log(`Hello ${user}`);
}

sayHelloToUser();

sayHelloToUser(); // user declared as a parameter. But when calling a function, an argument is needed not to get undefined result

// Example 4
let arr = [1,2,3];
console.log(arr[3]);
let arr = [1, 2, 3];
console.log(arr[3]); // The index has been given is not existing or NOT DEFINED in the variable
9 changes: 8 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
*/

function evenNumbers(n) {
// TODO
// TODO
const arr = [];
let i = 0;
while (i < n) {
arr.push(2 * i);
i++;
}
console.log(arr.toString());
}

evenNumbers(3); // should output 0,2,4
Expand Down
28 changes: 18 additions & 10 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
*/

const BIRTHDAYS = [
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
"July 17th",
"September 28th",
"November 15th"
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
"July 17th",
"September 28th",
"November 15th",
];

function findFirstJulyBDay(birthdays) {
// TODO
// TODO

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

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

function evenNumbersSum(n) {
// TODO
let sum = 0;
let i = 0;
do {
sum += 2 * i;
i++;
}while (i < n);
return sum;
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down