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: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/node_modules/
/package-lock.json
/node_modules/
/package-lock.json
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"jira-plugin.workingProject": ""
}
71 changes: 35 additions & 36 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
/*
By now, you would have already seen "undefined", either in an error message or being output from your program.
But what does it mean? undefined represents the absence of a value.

In some cases, undefined will be used by a programmer intentionally, and they will write code to handle it.
But usually, when you see undefined - it means something has gone wrong!

Below are 4 typical examples of when you would see undefined.
For each example, can you explain why we are seeing undefined?
*/

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


// Example 2
function sayHello() {
let message = "Hello";
}

let hello = sayHello();
console.log(hello);


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

sayHelloToUser();


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
/*
By now, you would have already seen "undefined", either in an error message or being output from your program.
But what does it mean? undefined represents the absence of a value.

In some cases, undefined will be used by a programmer intentionally, and they will write code to handle it.
But usually, when you see undefined - it means something has gone wrong!

Below are 4 typical examples of when you would see undefined.
For each example, can you explain why we are seeing undefined?
*/

// Example 1
let a;
console.log(a); // the variable a has no assigned value


// Example 2
function sayHello() {
let message = "Hello"; // message has not been declared
}

let hello = sayHello();
console.log(hello); // say hello has no parameters


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


// Example 4
let arr = [1,2,3];
console.log(arr[3]); // in the array there are in indexes 0,1,2 ,but no three
43 changes: 29 additions & 14 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
/*
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.
The list of numbers should start with 0. n is being passed in as a parameter.
*/

function evenNumbers(n) {
// TODO
}

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
/*
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.
The list of numbers should start with 0. n is being passed in as a parameter.
*/

let n = 0;
let number = 0;

function evenNumbers(n) {
const list = [];
while (number < n && n> 0) {
list.push(number * 2);
number++;
}
return list.join(",");
}
console.log(evenNumbers(3));
console.log(evenNumbers(0));
console.log(evenNumbers(10));


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



58 changes: 35 additions & 23 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
/*
Loops can be useful when working with arrays.
In the below example, imagine we've defined an array holding the birthdays of your closest friends.
Use a while loop to search through the array until you find the first birthday in July, then return that birthday from the function.
*/

const BIRTHDAYS = [
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
"July 17th",
"September 28th",
"November 15th"
];

function findFirstJulyBDay(birthdays) {
// TODO
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
/*
Loops can be useful when working with arrays.
In the below example, imagine we've defined an array holding the birthdays of your closest friends.
Use a while loop to search through the array until you find the first birthday in July, then return that birthday from the function.
*/

const BIRTHDAYS = [
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
"July 17th",
"September 28th",
"November 15th"
];
let i = 0;
function findFirstJulyBDay(birthdays) {
while (birthdays !== BIRTHDAYS) {
i++;
return BIRTHDAYS[5];
}
}

// let i = 0;
// let firstJuly = BIRTHDAYS.length;
// function findFirstJulyBDay(birthdays) {
// while (i < firstJuly ) {
// let = BIRTHDAYS[5];
// i++;
// }
// }

console.log(findFirstJulyBDay(i)); // should output "July 11th"
50 changes: 36 additions & 14 deletions 1-exercises/D-do-while/exercise.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
/*
Sometimes when using loops, we'll want to execute the body of the loop at least once. We can make sure this happens by using a do-while loop.
- If the condition in a while loop is initially false, the body of the loop will never execute
- But in a do-while loop, because the condition is checked after the body, we know that it will always execute at least once

Using a do-while loop, write a function which returns the sum of the first n even numbers (starting from 0)
*/

function evenNumbersSum(n) {
// TODO
}

console.log(evenNumbersSum(3)); // should output 6
console.log(evenNumbersSum(0)); // should output 0
/*
Sometimes when using loops, we'll want to execute the body of the loop at least once. We can make sure this happens by using a do-while loop.
- If the condition in a while loop is initially false, the body of the loop will never execute
- But in a do-while loop, because the condition is checked after the body, we know that it will always execute at least once

Using a do-while loop, write a function which returns the sum of the first n even numbers (starting from 0)
*/

let n = 0;
let number = 0;
let i = 0;
let x = i;
let y = i;

function evenNumbersSum(n) {
const list = [];
do {
n += 2;
list.push(n + n);
n++;
} while (n % 2);
return list.reduce((x, y) => x + y, 0);
}


// function evenNumbers(n) {
// const list = [];
// while (number < n && n > 0) {
// list.push(number * 2);
// number++;
// }
// return list.join(",");
// }

console.log(evenNumbersSum(3)); // should output 6
console.log(evenNumbersSum(0)); // should output 0
console.log(evenNumbersSum(10)); // should output 90
31 changes: 17 additions & 14 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/*
for loops can be useful when we already know exactly how many times we want to loop.

Change the while loop below into a for loop.
*/


// Change the below code to use a for loop instead of a while loop.
let i = 0;
while(i < 26) {
console.log(String.fromCharCode(97 + i));
i++;
}
// The output shouldn't change.
/*
for loops can be useful when we already know exactly how many times we want to loop.

Change the while loop below into a for loop.
*/


// Change the below code to use a for loop instead of a while loop.
let i = 0;
for (let i = 65; i <= 90; i++) {
console.log(String.fromCharCode(i));
}
// while(i < 26) {
// console.log(String.fromCharCode(97 + i));
// i++;
// }
// The output shouldn't change.
81 changes: 42 additions & 39 deletions 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
/*
for loops can be useful when we already know exactly how many times we want to loop.

Below we have 2 arrays which have exactly the same number of values.
- The first array is a list of writers
- The second array is a list of ages
The writers in the first array correspond with the ages in the second array.
For example, Virginia Woolf is 59 years old.

Using a for loop, output to the console a line about the age of each writer.
*/

const WRITERS = [
"Virginia Woolf",
"Zadie Smith",
"Jane Austen",
"Bell Hooks",
"Yukiko Motoya"
]

const AGES = [
59,
40,
41,
63,
49
];

// TODO - Write for loop code here

/*
The output should look something like this:

Virginia Woolf is 59 years old
Zadie Smith is 40 years old
Jane Austen is 41 years old
Bell Hooks is 63 years old
Yukiko Motoya is 49 years old
*/
/*
for loops can be useful when we already know exactly how many times we want to loop.

Below we have 2 arrays which have exactly the same number of values.
- The first array is a list of writers
- The second array is a list of ages
The writers in the first array correspond with the ages in the second array.
For example, Virginia Woolf is 59 years old.

Using a for loop, output to the console a line about the age of each writer.
*/

const WRITERS = [
"Virginia Woolf",
"Zadie Smith",
"Jane Austen",
"Bell Hooks",
"Yukiko Motoya"
]

const AGES = [
59,
40,
41,
63,
49
];

let combined = [];
for (let index = 0; index < WRITERS.length; index++) {
console.log(`${WRITERS[index]} is ${AGES[index]} years old.`);
}

/*
The output should look something like this:

Virginia Woolf is 59 years old
Zadie Smith is 40 years old
Jane Austen is 41 years old
Bell Hooks is 63 years old
Yukiko Motoya is 49 years old
*/
46 changes: 30 additions & 16 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
/*
A for-of loop is a easy and way of looping through the elements of an array, string or any other "iterable object" (think sequence of elements).
*/

// TODO Use a for-of loop to output each of the tube stations below.
let tubeStations = [
"Aldgate",
"Baker Street",
"Picadilly Circus",
"Oxford Street",
"Tottenham Court Road"
];


// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";
/*
A for-of loop is a easy and way of looping through the elements of an array, string or any other "iterable object" (think sequence of elements).
*/

// TODO Use a for-of loop to output each of the tube stations below.
let tubeStations = [
"Aldgate",
"Baker Street",
"Picadilly Circus",
"Oxford Street",
"Tottenham Court Road"
];

let station = "";
for (const index of tubeStations) {
station += index;
console.log(index);
}

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

for (const CYF of str) {
letters += CYF;
CYF + "";
console.log(CYF.toUpperCase());
}


Loading