-
-
Notifications
You must be signed in to change notification settings - Fork 279
London 9 Lovelace - Oleksii Chepurnyi - JavaScript Core1 - Week 3 #171
base: main
Are you sure you want to change the base?
Changes from all commits
ae59b09
fcc495a
3962bfd
28d1d70
aa6d319
406c508
6fce5b7
7f597cc
d03c851
303bc13
0da3674
501bd14
8e49a5d
2e7b191
817e682
06c7573
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 |
|---|---|---|
|
|
@@ -7,9 +7,16 @@ | |
| */ | ||
|
|
||
| function evenNumbersSum(n) { | ||
| // TODO | ||
| } | ||
| let i = 0; | ||
| let sum = 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. too much indentation |
||
| sum = sum + i*2; | ||
| i++; | ||
| } | ||
| while(i < n ); | ||
|
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. whitespace missing before |
||
| return sum; | ||
| } | ||
| console.log("The sum of first three even numbers equal ", evenNumbersSum(3)); // should output 6 | ||
| console.log("The sum of first zero even numbers equal ", evenNumbersSum(0)); // should output 0 | ||
| console.log("The sum of first ten even numbers equal ", evenNumbersSum(10)); // should output 90 | ||
|
|
||
| console.log(evenNumbersSum(3)); // should output 6 | ||
| console.log(evenNumbersSum(0)); // should output 0 | ||
| console.log(evenNumbersSum(10)); // should output 90 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,11 @@ const AGES = [ | |
| ]; | ||
|
|
||
| // TODO - Write for loop code here | ||
|
|
||
| /* | ||
| let i = 0; | ||
|
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. you don't need to declare |
||
| for (let i = 0; i < 5; i++) { | ||
| console.log(`${WRITERS[i]} is ${AGES[i]} years old` ); | ||
| } | ||
| /*"years old" | ||
| The output should look something like this: | ||
|
|
||
| Virginia Woolf is 59 years old | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,16 @@ | |
| let tubeStations = [ | ||
| "Aldgate", | ||
| "Baker Street", | ||
| "Picadilly Circus", | ||
| "Oxford Street", | ||
| "Tottenham Court Road" | ||
| "Canada Water", | ||
| "Forest Hill", | ||
| " " | ||
| ]; | ||
|
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 did you change the list? |
||
|
|
||
| for (const element of tubeStations) { | ||
| console.log(element); | ||
| } | ||
|
|
||
| // TODO Use a for-of loop to capitalise and output each letter in the string seperately. | ||
| let str = "codeyourfuture"; | ||
| for (let element of str) { | ||
| console.log(element.toUpperCase()); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| return allArticleTitles.filter((items) => items.length < 65); | ||
|
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 works perfectly, well done. |
||
| } | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,36 @@ | |
| Using a loop, complete the function below so it returns the factorial of the number being passed in. | ||
| */ | ||
|
|
||
| function factorial(input) { | ||
| function factorial(n) { | ||
| // TODO | ||
| let result = 1; | ||
| while (n) { | ||
| result *= n--; | ||
| } | ||
|
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 works, but some teams prefer not to use |
||
| return result; | ||
| } | ||
| console.log("Factorial number 2 = ", factorial(2)); | ||
| console.log("factorial number 3 = ", factorial(3)); | ||
| console.log("factorial number 5 = ", factorial(5)); | ||
| console.log("factorial number 10 = ", factorial(10)); | ||
|
|
||
|
|
||
| /* sol 2 | ||
| function factorial(n) { | ||
| if (n === 1) { | ||
| return 1; | ||
| } | ||
|
|
||
| return n * factorial(n - 1); | ||
| } | ||
|
|
||
| alert(factorial(1) === 1); | ||
| alert(factorial(2) === 2); | ||
| alert(factorial(3) === 6); | ||
| alert(factorial(4) === 24); | ||
| alert(factorial(5) === 120); | ||
| */ | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
| test("3! should be 6", () => { | ||
|
|
||
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.
Very good. You can also write it in fewer lines with
find()