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
8 changes: 4 additions & 4 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
For each example, can you explain why we are seeing undefined?
*/

// Example 1
/the letter a was not assigned to anything/ Example 1
let a;
console.log(a);


// Example 2
/there is no parameter set inside the sayHello brackets/ Example 2
function sayHello() {
let message = "Hello";
}
Expand All @@ -23,14 +23,14 @@ let hello = sayHello();
console.log(hello);


// Example 3
/the full fuction name is not stated in the console log/ Example 3
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();


// Example 4
/the maxiimum number in the array is 2/ Example 4
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 @@ -6,6 +6,14 @@
*/

function evenNumbers(n) {
let i = 0;
let evenArray = [];

while (i < n) {
evenArray.push(i * 2);
i++;
}
console.log(evenArray.join(', '))
// TODO
}

Expand Down
13 changes: 11 additions & 2 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ const BIRTHDAYS = [
];

function findFirstJulyBDay(birthdays) {
// TODO
}
let i = 0;
let myBdayCheck;

while (i < birthdays.length - 1) {
myBdayCheck = birthdays[i];

if (myBdayCheck.startsWith("July")) {
return myBdayCheck;
}
i++;
}
}
console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
8 changes: 8 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,14 @@

function evenNumbersSum(n) {
// TODO
sumNum = 0;
i = 0;

do {
sumNum = sumNum + i * 2
i++;
} while ( i < n );
return sumNum;
}

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

// Change the below code to use a for loop instead of a while loop.
let i = 0;
while(i < 26) {

for (i < 26; i++;) {
console.log(String.fromCharCode(97 + i));
i++;
}


// The output shouldn't change.


11 changes: 10 additions & 1 deletion 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@







/*
for loops can be useful when we already know exactly how many times we want to loop.

Expand Down Expand Up @@ -27,7 +34,9 @@ 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
7 changes: 6 additions & 1 deletion 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ let tubeStations = [
"Oxford Street",
"Tottenham Court Road"
];

for (const station of tubeStations) {
consolelog(tubeStations.toUpperCase());

// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";
for (let i = 0; i < str.length; i ++) {
console.log(str[i].toUpperCase())
}
}
7 changes: 7 additions & 0 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@

function getTemperatureReport(cities) {
// TODO

let tempArray = [];
for (let city of cities) {
tempArray.push(`The temperature in ${city} is ${temperatureService(city)} degrees`);
}
return tempArray;

}


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

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
}
let num;
do {
(num = generateRandomNumber());
} while (num <= 50);

return num;
}
/* ======= TESTS - DO NOT MODIFY ===== */

test("Returned value should always be greater than 50", () => {
Expand Down
34 changes: 32 additions & 2 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@
The home page of the web site has a headline section, which only has space for article titles which are 65 characters or less.
Implement the function below, which will return a new array containing only article titles which will fit.
*/
const allArticleTitles = [
"Streaming wars drive media groups to spend more than $100bn on new content",
"Amazon Prime Video India country head: streaming is driving a TV revolution",
"Aerospace chiefs prepare for bumpy ride in recovery of long-haul flights",
"British companies look to muscle in on US retail investing boom",
"Libor to take firm step towards oblivion on New Year's Day",
"Audit profession unattractive to new recruits, says PwC boss",
"Chinese social media users blast Elon Musk over near miss in space",
"Companies raise over $12tn in 'blockbuster' year for global capital markets",
"The three questions that dominate investment",
"Brussels urges Chile's incoming president to endorse EU trade deal",
];

function potentialHeadlines(allArticleTitles) {
// TODO
let titles = [];

for (const title in allArticleTitles) {
if (titles.length <= 65) {
titles.push(title);
}
}
return titles; // TODO
}

/*
Expand All @@ -14,7 +34,17 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let fewWords = allArticleTitles[0];
let words = allArticleTitles[0].split(" ").length;

for (let i = 0; i < allArticleTitles.length; i++) {
let theWordArrapy = allArticleTitles[i].split(" ").length;
if (theWordArray < words) {
fewWords = allArticleTitles[i];
}
words = theWordArrapy;
}
return fewWords;
}

/*
Expand Down