-
-
Notifications
You must be signed in to change notification settings - Fork 475
update #436
base: master
Are you sure you want to change the base?
update #436
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "editor.formatOnPaste": true, | ||
| "editor.formatOnSave": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| console.log("Hello world"); | ||
|
|
||
| console.log('Hello World. I just started learning JavaScript!') | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `greeting` | ||
|
|
||
| var 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,7 @@ | ||
| // Start by creating a variable `message` | ||
| var message = "This is a string"; | ||
| var messageType = typeof message; | ||
|
|
||
| console.log(messageType); | ||
|
|
||
|
|
||
| console.log(message); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `message` | ||
| var message = "Hello, my name is "; | ||
| var name = "Micheal"; | ||
|
|
||
| var greeting = message + name; | ||
| console.log(greeting); | ||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `message` | ||
| const name = " Daniel "; | ||
| name = "Daniel"; | ||
| var nameLowerCase = name.toLowerCase(); | ||
|
|
||
| console.log(nameLowerCase); | ||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| const name = " Daniel "; | ||
| name = "Daniel"; | ||
| var nameLowerCase = name.toLowerCase().trim(); | ||
|
|
||
| console.log(nameLowerCase); | ||
|
|
||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,6 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| numberOfStudents = 15; | ||
| numberOfMentors = 8; | ||
| total = numberOfMentors + numberOfStudents | ||
|
Comment on lines
+2
to
+4
Member
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. Variables in JavaScript need to be "declared"; this means you prefix the variable name with |
||
|
|
||
| console.log(total); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| var preciseAge = 30.612437; | ||
| var roughAge = Math.round(preciseAge); | ||
| numberOfStudents = 15; | ||
| numberOfMentors = 8; | ||
| total = numberOfMentors + numberOfStudents | ||
| var percentageOfStudents = (numberOfStudents/total)*100 | ||
| let percentageOfMentors = (numberOfMentors/total)*100 | ||
| var roughStudents = Math.round(percentageOfStudents); | ||
| var roughMentors = Math.round(percentageOfMentors); | ||
| console.log(roughMentors); | ||
| console.log(roughStudents); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return Number*.5 | ||
|
Member
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. variables are case-sensitive; in this case you want to refer to the |
||
| } | ||
|
|
||
| var result = halve(12); | ||
| var result = halve(number); | ||
|
|
||
| console.log(result); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| return number*3 | ||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Declare your function first | ||
|
|
||
| function name(a,b) { | ||
| return a/b | ||
|
Member
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. What would happen if |
||
|
|
||
| } | ||
| var result = divide(3, 4); | ||
|
|
||
| console.log(result); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Write your function here | ||
|
|
||
| function name(a,b) { | ||
| return | ||
| } | ||
| var greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Declare your function first | ||
|
|
||
| function name(a,b) { | ||
| return a+b | ||
|
|
||
| } | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| var sum= name(1,2) | ||
| console.log(sum); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| // Declare your function here | ||
| function createLongGreeting(a, b) { | ||
| return "I am " + a + " and I am " + b + " years old" | ||
|
Member
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. As a general comment, how might you rewrite this as a template string? Usually, template strings are preferred to string concatenation (especially when there are many variables involved), as it's usually more readable. |
||
| } | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,13 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
|
|
||
| function calculateSalesTax() {} | ||
|
|
||
| function calculateSalesTax(sales) { | ||
| const calcTax = sales * 0.2 + sales; | ||
| return calcTax; | ||
| } | ||
|
Comment on lines
9
to
+14
Member
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're declaring the same function name twice here, which is why one of your tests is failing. You can remove the declaration on line 9. |
||
| /* | ||
| CURRENCY FORMATTING | ||
| =================== | ||
|
|
@@ -16,8 +21,10 @@ function calculateSalesTax() {} | |
|
|
||
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(sales) { | ||
| return "£" + calculateSalesTax(sales).toFixed(2); | ||
| n | ||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
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.
try to avoid using
var; it can cause issues with scoping https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/ (you're not expected to understand what this means currently, just here in case you're interested). Try to always useconst, then, if the variable needs reassigning, delcare withletinstead