Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Glasgow_6 - Artem Filkovskyi - JS1 - Week_3 #259

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
14 changes: 10 additions & 4 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
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!

Expand All @@ -13,24 +13,30 @@
let a;
console.log(a);

// In this case "a" variable was just created and no values were assigned to it

// Example 2
function sayHello() {
let message = "Hello";
let message = 'Hello';
console.log(message);
}

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

// The first line is the result of calling sayHello, which logs "Hello" to the console. The second line is the value of hello variable, which is undefined. This is because the sayHello function does not return a value, so when it is called and assigned to the hello variable, the value of hello is undefined.

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

sayHelloToUser();

// This function prints "Hello undefined" in the console because function sayHelloToUser accepts parameter called "user". However, this function was invoked without any parameter, and this is why we get such result in the console.

// Example 4
let arr = [1,2,3];
let arr = [1, 2, 3];
console.log(arr[3]);

// Array "arr" contains three values, but when we trying to console.log arr[3], we actually asking to console element number 4, which doesn't exists in this case.
8 changes: 5 additions & 3 deletions 1-exercises/B-array-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
*/

let numbers = []; // add numbers from 1 to 10 into this array
let mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares
numbers.push(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let mentors = []; // Create an array with the names of the mentors: Daniel, Irina and Rares
mentors.push('Daniel', 'Irina', 'Rares');

/*
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
console.log(numbers);
console.log(mentors);

/*
/*
EXPECTED RESULT
---------------
[1,2,3,4,5,6,7,8,9,10]
Expand Down
10 changes: 5 additions & 5 deletions 1-exercises/C-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
*/

function first(arr) {
return; // complete this statement
return arr[0];
}

function last(arr) {
return; // complete this statement
return arr[arr.length - 1];
}

/*
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
let numbers = [1, 2, 3];
let names = ["Irina", "Ashleigh", "Mozafar", "Joe"];
let names = ['Irina', 'Ashleigh', 'Mozafar', 'Joe'];

console.log(first(numbers));
console.log(last(numbers));
console.log(last(names));

/*
/*
EXPECTED RESULT
---------------
1
Expand Down
5 changes: 3 additions & 2 deletions 1-exercises/C-array-get-set/exercises2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
*/

let numbers = [1, 2, 3]; // Don't change this array literal declaration
numbers[3] = 4;

/*
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
console.log(numbers);

/*
/*
EXPECTED RESULT
---------------
[1, 2, 3, 4]
Expand Down
19 changes: 5 additions & 14 deletions 1-exercises/D-for-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@
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 WRITERS = ['Virginia Woolf', 'Zadie Smith', 'Jane Austen', 'Bell Hooks', 'Yukiko Motoya'];

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

// 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
27 changes: 17 additions & 10 deletions 1-exercises/E-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
*/

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

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

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
70 changes: 34 additions & 36 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Imagine we're making a weather app!

We have a list of cities that the user wants to track.
We also already have a temperatureService function which will take a city as a parameter and return a temparature.

Expand All @@ -12,52 +12,50 @@
*/

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


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

function temperatureService(city) {
let temparatureMap = new Map();

temparatureMap.set('London', 10);
temparatureMap.set('Paris', 12);
temparatureMap.set('Barcelona', 17);
temparatureMap.set('Dubai', 27);
temparatureMap.set('Mumbai', 29);
temparatureMap.set('São Paulo', 23);
temparatureMap.set('Lagos', 33);
return temparatureMap.get(city);
let temparatureMap = new Map();

temparatureMap.set('London', 10);
temparatureMap.set('Paris', 12);
temparatureMap.set('Barcelona', 17);
temparatureMap.set('Dubai', 27);
temparatureMap.set('Mumbai', 29);
temparatureMap.set('São Paulo', 23);
temparatureMap.set('Lagos', 33);

return temparatureMap.get(city);
}

test("should return a temperature report for the user's cities", () => {
let usersCities = [
"London",
"Paris",
"São Paulo"
]

expect(getTemperatureReport(usersCities)).toEqual([
"The temperature in London is 10 degrees",
"The temperature in Paris is 12 degrees",
"The temperature in São Paulo is 23 degrees"
]);
let usersCities = ['London', 'Paris', 'São Paulo'];

expect(getTemperatureReport(usersCities)).toEqual([
'The temperature in London is 10 degrees',
'The temperature in Paris is 12 degrees',
'The temperature in São Paulo is 23 degrees',
]);
});

test("should return a temperature report for the user's cities (alternate input)", () => {
let usersCities = [
"Barcelona",
"Dubai"
]

expect(getTemperatureReport(usersCities)).toEqual([
"The temperature in Barcelona is 17 degrees",
"The temperature in Dubai is 27 degrees"
]);
let usersCities = ['Barcelona', 'Dubai'];

expect(getTemperatureReport(usersCities)).toEqual([
'The temperature in Barcelona is 17 degrees',
'The temperature in Dubai is 27 degrees',
]);
});

test("should return an empty array if the user hasn't selected any cities", () => {
expect(getTemperatureReport([])).toEqual([]);
});
expect(getTemperatureReport([])).toEqual([]);
});
Loading