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
10 changes: 5 additions & 5 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
*/

// Example 1
let a;
let a; // There is nothing equal with variable "a"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, I think maybe a language issue, the best way to say it is that there is no value assigned to variable "a". Just because equal sounds like "a === a" etc but I knew what you meant 👍

console.log(a);


// Example 2
function sayHello() {
let message = "Hello";
let message = "Hello";// This function does not return anything, so definition is not enough.
}

let hello = sayHello();
console.log(hello);
console.log(hello);// Variable defined but function must be defined too.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted, there are no parethesis console.log(hello())



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

sayHelloToUser();
sayHelloToUser(); // There must be a value inside of the paranthesis to make our function defined.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function will be defined without a value, we're just calling it wrong, so you are correct we need a value.



// Example 4
let arr = [1,2,3];
console.log(arr[3]);
console.log(arr[3]); // The index has been given is not existing or NOT DEFINED in the variable
8 changes: 7 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/

function evenNumbers(n) {
// TODO
let output = [];
let i =0;
while(output.length<n){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this doesn't work Cuneyt, if I call this function with evenNumbers(10) it exceeds 10 in its return, it gives me:

[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]

Let me know if you want help with this one in the group chat.

output.push(i);
i=i+2
}
console.log(output)
}

evenNumbers(3); // should output 0,2,4
Expand Down
8 changes: 7 additions & 1 deletion 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const BIRTHDAYS = [
];

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

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
12 changes: 11 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,17 @@
*/

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

} while (counter<n);

return sum;
}

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


// 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.
4 changes: 3 additions & 1 deletion 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const AGES = [
];

// TODO - Write for loop code here

for(let i = 0;i<5;i++){
console.log(`${WRITERS[i]} is ${AGES[i]} years old`)
}
/*
The output should look something like this:

Expand Down
7 changes: 7 additions & 0 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ 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.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 output = []
for(let i of cities){
output.push(`The temperature in ${i} is ${temperatureService(i)} degrees`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of backticks here

}
return output
}


Expand Down
17 changes: 11 additions & 6 deletions 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@

// This function shouldn't be changed
function generateRandomNumber() {
console.log("Generating number...");
console.log("Generating number...")
return Math.round(Math.random() * 100);
}

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
}
}

function getRandomNumberGreaterThan50() {
let numbersInArray = []
do{
numbersInArray = generateRandomNumber()
}while(numbersInArray<51)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you used an array here, it does seem to work but maybe you can teach me something after this review 😂

I'd have gone for an integer / Number.

return numbersInArray
}


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

Expand Down
42 changes: 36 additions & 6 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 fitTitles = [];
for(let i in allArticleTitles){
if(allArticleTitles[i].length<=65){
fitTitles.push(allArticleTitles[i])
}
}
return fitTitles
}

/*
Expand All @@ -14,24 +20,48 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
}
let lengthOfTitles = []
for(let i in allArticleTitles){
lengthOfTitles.push(allArticleTitles[i].split(" ").length)
}
let minimumTitlesIndex = lengthOfTitles.indexOf(Math.min(...lengthOfTitles))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little hard to read but you did it right. You created an array of words and then got the minimum and returned it.

return allArticleTitles[minimumTitlesIndex]

}


/*
The editor of the FT has realised that headlines which have numbers in them get more clicks!
Implement the function below to return a new array containing all the headlines which contain a number.
(Hint: remember that you can also loop through the characters of a string if you need to)
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
}
let output = []
for(let i in allArticleTitles){

if(allArticleTitles[i].match(/[0-9]/g) !== null){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of regular expressions, @Ekremteke actually simplified this with the /d operator. /d is a shortcut for 0-9 both are correct however I just felt it would be good to share that shortcut.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That made sense, thank you.

output.push(allArticleTitles[i])
}

}
return output
}

/*
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
let allIntegers = []
for(let i in allArticleTitles){
allIntegers.push(allArticleTitles[i].length)
}
let total = 0;
for(let i = 0; i < allIntegers.length; i++) {
total += allIntegers[i];
}
let average = total / allIntegers.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did great here, I would advise using new lines to help separate your code to help the readability. Split it up into chunks of separate logic.

return Math.round(average)
}


Expand Down
29 changes: 26 additions & 3 deletions 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO

let arrayOfAverage = []
for(let i of closingPricesForAllStocks){
let total = 0;
for(let j in i){
total += i[j];
}
let a = total/i.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge advocate for your variable naming here, you have i, j, a and b - Imagine if this code was 500 lines long, we'd need to study it closely to know what was happening.

Other than that, good job! There are a couple other ways to do this but you succeeded in completed the exercise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really need to get used to it.

let b = Number(a.toFixed(2))
arrayOfAverage.push(b)
}
return arrayOfAverage
}

/*
Expand All @@ -48,7 +59,12 @@ function getAveragePrices(closingPricesForAllStocks) {
The price change value should be rounded to 2 decimal places, and should be a number (not a string)
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
let priceChanges = []
for(let array of closingPricesForAllStocks){
let output = array[array.length-1]-array[0];
priceChanges.push(Number(output.toFixed(2)))
}
return priceChanges
}

/*
Expand All @@ -64,7 +80,14 @@ function getPriceChanges(closingPricesForAllStocks) {
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
let returnThisArray = []
for(let index in closingPricesForAllStocks){
let largestNumber = Math.max(...closingPricesForAllStocks[index]);
let outputWithQuote = `The highest price of ${stocks[index].toUpperCase()} in the last 5 days was ${largestNumber.toFixed(2)}`
returnThisArray.push(outputWithQuote)
}
return returnThisArray

}


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

function factorial(input) {
// TODO
let total = 1;
for(let index=input;index>0;index--){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always remember to include spaces, they're not needed by the compiler or processor which reads the code, but it helps us read it better as developers 😅

I'm not sure you actually completed this task, we can talk about it in the hawk channel if you want.

total *= index
}
return total
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
6 changes: 5 additions & 1 deletion 3-extra/2-array-of-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
*/

function getHighestRatedInEachGenre(books) {
// TODO
for(let everyObjects of books){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you know this function isn't complete 😂

If you need help with this one, please talk in the hawk channel, myself and the others can help you out.

for(let key of everyObjects){

}
}
}


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
let fib = [0,1];

for(let index = 0; fib.length<n;index++){
fib.push(fib[index]+fib[index+1])
}
return fib
}

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