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 @@ -10,13 +10,13 @@
*/

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


// Example 2
function sayHello() {
let message = "Hello";
let message = "Hello"; // there is no return value inside the function
}

let hello = sayHello();
Expand All @@ -28,9 +28,9 @@ function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();
sayHelloToUser(); //there is no argument


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
console.log(arr[3]); //index 3 doesn't exit
12 changes: 10 additions & 2 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
*/

function evenNumbers(n) {
// TODO
}
let arr = [];
let counter = 0;
let evenNum = 0;
while (counter < n) {
arr.push(evenNum);
evenNum += 2;
counter ++;
}
console.log(arr.join());
}

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

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

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

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

} while(counter < 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(10)); // should output 90
console.log(evenNumbersSum(20));
5 changes: 2 additions & 3 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@


// 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.
5 changes: 5 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,11 @@ 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
8 changes: 8 additions & 0 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ let tubeStations = [
"Tottenham Court Road"
];

for (let x of tubeStations){
console.log(x);
}


// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";

for (let x of str){
console.log(x.toUpperCase());
}
6 changes: 5 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
*/

function getTemperatureReport(cities) {
// TODO
let arr = [];
for (let i=0; i<cities.length; i++){
arr.push(`The temperature in ${cities[i]} is ${temperatureService(cities[i])} degrees`);
}
return arr;
}


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

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

let randomNum = generateRandomNumber();
if (randomNum > 50){
return randomNum;
}
i++;
} while(i < 51)

}

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

/*
The editor of the FT likes short headlines with only a few words!
Expand All @@ -23,15 +29,21 @@ 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 arr = [];
for (let i = 0; i < allArticleTitles; i++){
if(allArticleTitles.includes()){

}
return arr;
}
}

/*
The Financial Times wants to understand what the average number of characters in an article title is.
Implement the function below to return this number - rounded to the nearest integer.
*/
function averageNumberOfCharacters(allArticleTitles) {
// TODO

}


Expand Down
9 changes: 8 additions & 1 deletion 3-extra/1-factorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
*/

function factorial(input) {
// TODO
if (input === 0 || input === 1){
return 1;
}

for (let i = input - 1; i >= 1; i--){
input *= i;
}
return input;
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
7 changes: 6 additions & 1 deletion 3-extra/3-fibonacci.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
*/

function generateFibonacciSequence(n) {
// TODO
const fib = [0, 1];

for (let i = 2; i < n; i++) {
fib[i] = fib[i-1] + fib[i-2];
}
return fib;
}

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