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

// Example 1
let a;
console.log(a);
console.log(a); //'a' hasn't been assigned a value


// Example 2
Expand All @@ -20,17 +20,16 @@ function sayHello() {
}

let hello = sayHello();
console.log(hello);
console.log(hello); //function doesn't return anything


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

sayHelloToUser();

sayHelloToUser(); //no argument given when calling the function.

// Example 4
let arr = [1,2,3];
console.log(arr[3]);
console.log(arr[3]); //The arrays start at 0, there is no array item at the 3rd index.
17 changes: 14 additions & 3 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
/*
while loops can be useful when you want to execute some code as long as some condition is true.

Using a while loop, complete the function below so it logs (using console.log) the first n even numbers as a comma-seperated string.
Using a while loop, complete the function below so it logs (using console.log) the first n even numbers as a comma-separated string.
The list of numbers should start with 0. n is being passed in as a parameter.
*/

function evenNumbers(n) {
// TODO
let i = 0;
let count = 1;
let zahraasBag = [];

while (count <= n) {
// console.log(`Loop${count} i:${i} n:${n} count:${count}`);
count = count + 1;
zahraasBag.push(i);
i = i + 2;
}

console.log(zahraasBag.join());
}

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
evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18
11 changes: 8 additions & 3 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ const BIRTHDAYS = [
"November 15th"
];

function findFirstJulyBDay(birthdays) {
// TODO
function findFirstJulyBDay(theToasterYouAreGoingToGiveMe) {
for (let pieceOfToast of theToasterYouAreGoingToGiveMe) {
// console.log(pieceOfToast);
if (pieceOfToast.includes("July")) {
return pieceOfToast;
}
}
}

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

function evenNumbersSum(n) {
// TODO

let i = 0;
let count = 1;
let sum = 0;

do {
i = i + 2;
count = count + 1;
sum = sum + i;
// console.log(sum);
} while (count < n);

return sum;
}

console.log(evenNumbersSum(3)); // should output 6
console.log(evenNumbersSum(0)); // should output 0
console.log(evenNumbersSum(10)); // should output 90
console.log(evenNumbersSum(3)); // should output 6 0+2+4 = 6
console.log(evenNumbersSum(0)); // should output 0 0
console.log(evenNumbersSum(10)); // should output 90 0+2+4+6+8+10+12+14+16+18 = 90
3 changes: 1 addition & 2 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

// Change the below code to use a for loop instead of a while loop.
let i = 0;
while(i < 26) {
for (let i = 0; i < 26; i++) {
console.log(String.fromCharCode(97 + i));
i++;
}
// The output shouldn't change.
3 changes: 3 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,9 @@ const AGES = [

// TODO - Write for loop code here

i = 0;
for (let )

/*
The output should look something like this:

Expand Down
23 changes: 21 additions & 2 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/
function potentialHeadlines(allArticleTitles) {
// TODO
let headlines = [];

for (headline)
}


function numberOfWords(title) {
// return no. of words in title
let wordsArray = title.split(' ').length
return wordsArray
}

/*
Expand All @@ -14,7 +23,17 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let lowestNumberOfWords;
let titleWithFewestWords;

for (let title of allArticleTitles) {
let numWords = numberOfWords(title);
if (lowestNumberOfWords === undefined || numWords < lowestNumberOfWords) {
lowestNumberOfWords = numWords;
titleWithFewestWords = title;
}
}
return titleWithFewestWords;
}

/*
Expand Down