-
-
Notifications
You must be signed in to change notification settings - Fork 476
London-class-8-Helena-Rog-JS-Week1 #240
Changes from all commits
b666c73
e34dff1
c8e4850
4330f19
2ec95ac
b70654a
a2a5d83
bf58195
2c7058e
9979206
0802d09
d84ea0b
a17a9b5
44197ba
f0d266d
4c09cbc
8cfcbfe
9e2f686
a131996
d09f81c
a01f90a
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 |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| console.log("Hello world"); | ||
| console.log("I've just started to learn JavaScript"); | ||
| console.log(500); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `greeting` | ||
|
|
||
| let greeting = "Hello World!"; | ||
|
|
||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
| let message = "This is a string"; | ||
| let messageType = typeof message; | ||
|
|
||
| console.log(message); | ||
| console.log(messageType); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `message` | ||
| let messageStart = "Hello, my name is "; | ||
| let myName = "Helen"; | ||
|
|
||
| let message = messageStart + myName; | ||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| // Start by creating a variable `message` | ||
| const myName = "Helen"; | ||
| const myNameLength = myName.length; | ||
| const message = | ||
| "Hello, my name is " + | ||
| myName + | ||
| " and my name is " + | ||
| myNameLength + | ||
| " characters long."; | ||
|
|
||
| console.log(myName); | ||
| console.log(myNameLength); | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| const name = " Daniel "; | ||
| let myName = " Helen "; | ||
| let myNameTrimmed = myName.trim(); | ||
| let myNameLength = myNameTrimmed.length; | ||
| let message = | ||
| "Hello, my name is " + | ||
| myNameTrimmed + | ||
| " and my name is " + | ||
| myNameLength + | ||
| " characters long."; | ||
|
|
||
| console.log(myNameLength); | ||
| console.log(myNameTrimmed); | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
|
|
||
| let numberOfStudents = 50; | ||
| let numberOfMentors = 25; | ||
| let total = numberOfStudents + numberOfMentors; | ||
| let message = "Total number of students and mentors: " + total; | ||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| let numberOfStudents = 15; | ||
| let numberOfMentors = 8; | ||
| let total = numberOfStudents + numberOfMentors; | ||
| let percentOfStudents = (numberOfStudents * 100) / total; | ||
| let roundPercentStudents = Math.round(percentOfStudents); | ||
| let percentOfMentors = (numberOfMentors * 100) / total; | ||
| let roundPercentMentors = Math.round(percentOfMentors); | ||
|
|
||
| console.log(roundPercentStudents); | ||
|
|
||
| console.log(roundPercentMentors); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number / 2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| let result = halve(34); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| return number * 3; | ||
| } | ||
|
|
||
| var result = triple(12); | ||
| let result = triple(12); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| function multiply(num1, num2) { | ||
| // Calculate the result of the function and return it | ||
| return num1 * num2; | ||
| } | ||
|
|
||
| // Assign the result of calling the function the variable `result` | ||
| var result = multiply(3, 4); | ||
| let result = multiply(3, 4); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Declare your function first | ||
| function divide(num1, num2) { | ||
| return num1 / num2; | ||
| } | ||
|
|
||
| var result = divide(3, 4); | ||
| let result = divide(3, 4); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Write your function here | ||
| function createGreeting(name) { | ||
| return "Hello, my name is " + name; | ||
| } | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
| let greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| // Declare your function first | ||
|
|
||
| function add(num1, num2) { | ||
| return num1 + num2; | ||
| } | ||
|
|
||
| let sum = add(13, 124); | ||
|
|
||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| // Declare your function here | ||
|
|
||
| function createLongGreeting (name, age) { | ||
| return "Hello, my name is " + name + " and I'm " + age + " years old" | ||
| } | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,29 @@ | ||
| var mentor1 = "Daniel"; | ||
| var mentor2 = "Irina"; | ||
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; | ||
| var mentor1 = "Daniel"; | ||
|
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. There's some indentation issues in the file -- basically, everything should start from the very left side, unless it's inside function brackets, or a for loop (you'll learn about these later) or something of this sort. |
||
| var mentor2 = "Irina"; | ||
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; | ||
|
|
||
| function helloGreeting(name) { | ||
| return name; | ||
| } | ||
|
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 function doesn't do anything as is -- all the work is being done by the other function. As per instructions, you should have:
|
||
| function upperCaseGreeting(helloGreeting) { | ||
| return ("Hello " + helloGreeting).toUpperCase(); | ||
| } | ||
|
|
||
| var greeting = helloGreeting; | ||
| var shoutyGreeting = upperCaseGreeting; | ||
|
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 is just renaming the function -- is this what you intended to do? |
||
|
|
||
|
|
||
| // console.log(greeting(mentor1)); | ||
| // console.log(greeting(mentor2)); | ||
| // console.log(greeting(mentor3)); | ||
| // console.log(greeting(mentor4)); | ||
| // console.log(greeting(mentor5)); | ||
|
|
||
| console.log(shoutyGreeting(mentor1)); | ||
| console.log(shoutyGreeting(mentor2)); | ||
| console.log(shoutyGreeting(mentor3)); | ||
| console.log(shoutyGreeting(mentor4)); | ||
| console.log(shoutyGreeting(mentor5)); | ||
|
|
||
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 start. JavaScript can be challenging and with practice we will get better.