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
4 changes: 4 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,10 @@
*/

function evenNumbers(n) {
let numbers = [0,2,4,6,8,10,12,14,16,18];
for(i=0; i<n ; i++){
console.log(numbers[i]);
}
// TODO
}

Expand Down
10 changes: 9 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,15 @@
*/

function evenNumbersSum(n) {
// TODO
numbers = [0,2,4,6,8,10,12,14,16,18,20,22,24]
let sum = 0;
let i = 0;
do {
sum += numbers[i];
i++;
}
while (i < n);
return sum;
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
3 changes: 3 additions & 0 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ while(i < 26) {
i++;
}
// The output shouldn't change.
for(i = 0; i < 26; i++) {
String.fromCharCode(97 + i);
}
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 @@ -26,6 +26,9 @@ const AGES = [
49
];

for(let i = 0; i < WRITERS.length; i++) {
console.log(`${WRITERS[i]} is ${AGES[i]} years old`);
}
// TODO - Write for loop code here

/*
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(let i of tubeStations) {
console.log(i);
}

// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";
for(let i of str) {
console.log(i);
}
5 changes: 4 additions & 1 deletion 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ function generateRandomNumber() {
}

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
do{
console.log(generateRandomNumber());
}
while (generateRandomNumber()>50)
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
20 changes: 18 additions & 2 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/
function potentialHeadlines(allArticleTitles) {
// TODO
let newArr = [];
for(let i=0;i<allArticleTitles.length;i++){
if (allArticleTitles[i].length<=65){
newArr.push(allArticleTitles[i]);
}
console.log(newArr);
}
}

/*
Expand All @@ -23,7 +29,17 @@ function titleWithFewestWords(allArticleTitles) {
(Hint: remember that you can also loop through the characters of a string if you need to)
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
let numbers = ["0","1","2","3","4","5","6","7","8","9"];
let newArr = [];
for(let i=0;i<allArticleTitles.length;i++){
for(let j=0;j<allArticleTitles[i].length;j++){
if (allArticleTitles[i][j] == numbers){
newArr.push(allArticleTitles[i]);
}

}
console.log(newArr);
}
}

/*
Expand Down
10 changes: 9 additions & 1 deletion 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
let sum = 0
for(let i=0;i<closingPricesForAllStocks.length;i++){
for(let j=0; j<closingPricesForAllStocks[i].length;j++){
return sum = sum + closingPricesForAllStocks[i];
}

console.log(`the average of ${STOCKS[i]} is ${sum/closingPricesForAllStocks[i].length}`);
}
console.log(sum);
}

/*
Expand Down