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

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

console.log(a);
// we can print the value because (a)was not declared. let a = 2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Techincally, it's been declared but not dinfied, but I get what you mean and it's right


// Example 2
function sayHello() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this function return undefined?

Expand All @@ -29,8 +30,10 @@ function sayHelloToUser(user) {
}

sayHelloToUser();
// the argument doesn't pass

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct



// Example 4
// This array has 3 elemente 0,1,2.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

let arr = [1,2,3];
console.log(arr[3]);
8 changes: 8 additions & 0 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

function evenNumbers(n) {
// TODO
const even =[0, 2, 4, 6, 8, 10, 12, 14, 16, 18];
let string = "";
let count = 0;
while(count < n) {
string += `${even[count]},`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looking good, love how you used ` They're so good :)

count++;
}
console.log(string);
}

evenNumbers(3); // should output 0,2,4
Expand Down
8 changes: 7 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,13 @@ const BIRTHDAYS = [
];

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Formatting's a bit off, but Prettier should automatically fix that for you, let me know if you need help there

count++;
}

}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
13 changes: 13 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,19 @@

function evenNumbersSum(n) {
// TODO
let counter = 0;
let sum = 0;
do {
if (counter % 2 === 0) {
sum += counter;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work

}
counter++;
} while (counter < n * 2);

console.log(sum);



}

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


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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!


for (let i = 0; i < 26; i++) {
console.log(String.fromCharCode(97 + i));}
// The output shouldn't change.
11 changes: 11 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,17 @@ 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`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

}


/*let i = 0;
while(i < WRITERS.length) {
console.log(`${WRITERS[i]} is ${AGES[i]} years old`);
i++;
}*/

/*
The output should look something like this:

Expand Down
7 changes: 7 additions & 0 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ let tubeStations = [
"Oxford Street",
"Tottenham Court Road"
];
for (station of tubeStations){
console.log(station);
}


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";
for (let put of str){
console.log(put.toLocaleUpperCase());
}

7 changes: 7 additions & 0 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ function getTemperatureReport(cities) {
// TODO
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file throws an exception when run, specfically a "ReferenceError: cities is not defined" Can you see why?

const temparatures = [];

for (let city of cities) {
temparatures.push(
`The temperature in ${city} is ${temperatureService(city)} degrees`
);
}

/* ======= TESTS - DO NOT MODIFY ===== */

Expand Down
8 changes: 8 additions & 0 deletions 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ function generateRandomNumber() {

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
let number = 0;
do{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work all tests pass on this one

number = generateRandomNumber();

} while ( number<= 50);
return number;

}
console.log(getRandomNumberGreaterThan50());

/* ======= TESTS - DO NOT MODIFY ===== */

Expand Down
27 changes: 27 additions & 0 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
return allArticleTitles.filter((article) => {
return article.length <= 65;
});
}

/*
Expand All @@ -15,6 +18,19 @@ function potentialHeadlines(allArticleTitles) {
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let wordLength = 100;
let index = 0;

allArticleTitles.forEach((article, i) => {
const split = article.split(" ");

if (split.length < wordLength) {
wordLength = split.length;
index = i;
}
});

return allArticleTitles[index];
}

/*
Expand All @@ -24,6 +40,9 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
return allArticleTitles.filter((article) => {
return /\d/.test(article);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, I'm not sure if you've been taught regular expressions yet but they're very useful beasts indeed

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, I'm not sure if you've been taught regular expressions yet but they're very useful beasts indeed

});
}

/*
Expand All @@ -34,6 +53,14 @@ function averageNumberOfCharacters(allArticleTitles) {
// TODO
}

let total = 0;

for (let article of allArticleTitles) {
total += article.length;
}

return Math.round(total / allArticleTitles.length);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line cause a problem. Can you see why?




/* ======= List of Articles - DO NOT MODIFY ===== */
Expand Down