-
-
Notifications
You must be signed in to change notification settings - Fork 279
LONDON-9-SAGHAR HOSSEINMARDI-JS-WEEK3 #201
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 |
|---|---|---|
|
|
@@ -13,24 +13,28 @@ | |
| let a; | ||
| console.log(a); | ||
|
|
||
| // variable a has no value. | ||
|
|
||
| // Example 2 | ||
| function sayHello() { | ||
| let message = "Hello"; | ||
| let message = "Hello"; | ||
| } | ||
|
|
||
| let hello = sayHello(); | ||
| console.log(hello); | ||
|
|
||
| // the function doesn't return anything and there is no value to be assigned to it | ||
|
|
||
| // Example 3 | ||
| function sayHelloToUser(user) { | ||
| console.log(`Hello ${user}`); | ||
| console.log(`Hello ${user}`); | ||
| } | ||
|
|
||
| sayHelloToUser(); | ||
|
|
||
| // there is no value for the parameter | ||
|
|
||
| // Example 4 | ||
| let arr = [1,2,3]; | ||
| let arr = [1, 2, 3]; | ||
| console.log(arr[3]); | ||
| // the index in console.log does not exist in an array | ||
|
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. Yes, the array has only 3 items so |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,15 @@ | |
| */ | ||
|
|
||
| function evenNumbers(n) { | ||
| // TODO | ||
| let num = 0; | ||
| let arr = []; | ||
| while (n > 0) { | ||
| arr.push(num); | ||
| num = num + 2; | ||
| n--; | ||
| } | ||
|
|
||
| console.log(arr); | ||
|
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 logs out the array fine, looks good. |
||
| } | ||
|
|
||
| evenNumbers(3); // should output 0,2,4 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,16 @@ | |
| */ | ||
|
|
||
| function evenNumbersSum(n) { | ||
| // TODO | ||
| let number = 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. Great 👍 |
||
| let sum = 0; | ||
| do { | ||
| sum = sum + number; | ||
| number = number + 2; | ||
| n--; | ||
| } while (n > 0); | ||
| return sum; | ||
| } | ||
|
|
||
| console.log(evenNumbersSum(3)); // should output 6 | ||
| console.log(evenNumbersSum(0)); // should output 0 | ||
| console.log(evenNumbersSum(10)); // should output 90 | ||
| console.log(evenNumbersSum(10)); // should output 90 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,23 +11,20 @@ | |
| */ | ||
|
|
||
| const WRITERS = [ | ||
| "Virginia Woolf", | ||
| "Zadie Smith", | ||
| "Jane Austen", | ||
| "Bell Hooks", | ||
| "Yukiko Motoya" | ||
| ] | ||
|
|
||
| const AGES = [ | ||
| 59, | ||
| 40, | ||
| 41, | ||
| 63, | ||
| 49 | ||
| "Virginia Woolf", | ||
| "Zadie Smith", | ||
| "Jane Austen", | ||
| "Bell Hooks", | ||
| "Yukiko Motoya", | ||
| ]; | ||
|
|
||
| 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"); | ||
|
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. Perfect |
||
| } | ||
| /* | ||
| The output should look something like this: | ||
|
|
||
|
|
||
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.
👍