-
-
Notifications
You must be signed in to change notification settings - Fork 279
NW5-Manchester-Sandra Duarte-JavaScript-core-1-Week3 #131
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,9 @@ | |
|
|
||
| // Example 1 | ||
| let a; | ||
| console.log(a); | ||
|
|
||
| console.log(a); | ||
| // we can print the value because (a)was not declared. let a = 2; | ||
|
|
||
| // Example 2 | ||
| function sayHello() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this function return undefined? |
||
|
|
@@ -29,8 +30,10 @@ function sayHelloToUser(user) { | |
| } | ||
|
|
||
| sayHelloToUser(); | ||
| // the argument doesn't pass | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct |
||
|
|
||
|
|
||
| // Example 4 | ||
| // This array has 3 elemente 0,1,2. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct |
||
| let arr = [1,2,3]; | ||
| console.log(arr[3]); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,14 @@ | |
|
|
||
| function evenNumbers(n) { | ||
| // TODO | ||
| const even =[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]; | ||
| let string = ""; | ||
| let count = 0; | ||
| while(count < n) { | ||
| string += `${even[count]},`; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All looking good, love how you used ` They're so good :) |
||
| count++; | ||
| } | ||
| console.log(string); | ||
| } | ||
|
|
||
| evenNumbers(3); // should output 0,2,4 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,13 @@ const BIRTHDAYS = [ | |
| ]; | ||
|
|
||
| function findFirstJulyBDay(birthdays) { | ||
| // TODO | ||
| // TODO | ||
| let count = 0; | ||
| while (count < birthdays.length){ | ||
| if(birthdays[count].includes("July")) return birthdays[count]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work! Formatting's a bit off, but Prettier should automatically fix that for you, let me know if you need help there |
||
| count++; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,19 @@ | |
|
|
||
| function evenNumbersSum(n) { | ||
| // TODO | ||
| let counter = 0; | ||
| let sum = 0; | ||
| do { | ||
| if (counter % 2 === 0) { | ||
| sum += counter; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work |
||
| } | ||
| counter++; | ||
| } while (counter < n * 2); | ||
|
|
||
| console.log(sum); | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| console.log(evenNumbersSum(3)); // should output 6 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,12 @@ | |
|
|
||
|
|
||
| // Change the below code to use a for loop instead of a while loop. | ||
| let i = 0; | ||
| /*let i = 0; | ||
| while(i < 26) { | ||
| console.log(String.fromCharCode(97 + i)); | ||
| i++; | ||
| } | ||
| }*/ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work! |
||
|
|
||
| for (let i = 0; i < 26; i++) { | ||
| console.log(String.fromCharCode(97 + i));} | ||
| // The output shouldn't change. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,17 @@ 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`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work! |
||
| } | ||
|
|
||
|
|
||
| /*let i = 0; | ||
| while(i < WRITERS.length) { | ||
| console.log(`${WRITERS[i]} is ${AGES[i]} years old`); | ||
| i++; | ||
| }*/ | ||
|
|
||
| /* | ||
| The output should look something like this: | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,14 @@ let tubeStations = [ | |
| "Oxford Street", | ||
| "Tottenham Court Road" | ||
| ]; | ||
| for (station of tubeStations){ | ||
| console.log(station); | ||
| } | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work! |
||
| // TODO Use a for-of loop to capitalise and output each letter in the string seperately. | ||
| let str = "codeyourfuture"; | ||
| for (let put of str){ | ||
| console.log(put.toLocaleUpperCase()); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,13 @@ function getTemperatureReport(cities) { | |
| // TODO | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file throws an exception when run, specfically a "ReferenceError: cities is not defined" Can you see why? |
||
| const temparatures = []; | ||
|
|
||
| for (let city of cities) { | ||
| temparatures.push( | ||
| `The temperature in ${city} is ${temperatureService(city)} degrees` | ||
| ); | ||
| } | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,15 @@ function generateRandomNumber() { | |
|
|
||
| function getRandomNumberGreaterThan50() { | ||
| // TODO - implement using a do-while loop | ||
| let number = 0; | ||
| do{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work all tests pass on this one |
||
| number = generateRandomNumber(); | ||
|
|
||
| } while ( number<= 50); | ||
| return number; | ||
|
|
||
| } | ||
| console.log(getRandomNumberGreaterThan50()); | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ | |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| return allArticleTitles.filter((article) => { | ||
| return article.length <= 65; | ||
| }); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -15,6 +18,19 @@ function potentialHeadlines(allArticleTitles) { | |
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| let wordLength = 100; | ||
| let index = 0; | ||
|
|
||
| allArticleTitles.forEach((article, i) => { | ||
| const split = article.split(" "); | ||
|
|
||
| if (split.length < wordLength) { | ||
| wordLength = split.length; | ||
| index = i; | ||
| } | ||
| }); | ||
|
|
||
| return allArticleTitles[index]; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -24,6 +40,9 @@ function titleWithFewestWords(allArticleTitles) { | |
| */ | ||
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| return allArticleTitles.filter((article) => { | ||
| return /\d/.test(article); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work, I'm not sure if you've been taught regular expressions yet but they're very useful beasts indeed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work, I'm not sure if you've been taught regular expressions yet but they're very useful beasts indeed |
||
| }); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -34,6 +53,14 @@ function averageNumberOfCharacters(allArticleTitles) { | |
| // TODO | ||
| } | ||
|
|
||
| let total = 0; | ||
|
|
||
| for (let article of allArticleTitles) { | ||
| total += article.length; | ||
| } | ||
|
|
||
| return Math.round(total / allArticleTitles.length); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line cause a problem. Can you see why? |
||
|
|
||
|
|
||
|
|
||
| /* ======= List of Articles - DO NOT MODIFY ===== */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Techincally, it's been declared but not dinfied, but I get what you mean and it's right