-
-
Notifications
You must be signed in to change notification settings - Fork 475
ZA2-Ntshumayelo Matho-JavaScript-Core-1-coursework-week1 #309
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 |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| console.log("Hello world"); | ||
| console.log("Hello World. I just started learning JavaScript!."); | ||
| console.log("I like playing piano."); | ||
| console.log(2 + 2); | ||
|
|
||
| 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); | ||
|
|
||
|
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. Nice! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `message` | ||
| let message = "This is a string"; | ||
| let messageType = typeof message; | ||
|
|
||
| console.log(message); | ||
| console.log(messageType); | ||
|
|
||
|
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! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
| let greetingStart = " Hello my name is "; | ||
| let name = "Ntshumayelo"; | ||
|
|
||
| console.log(message); | ||
| let greeting = greetingStart + name; | ||
| console.log(greeting); | ||
|
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 work on providing a working solution. For future reference: attention to detail is really important for a program. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
| let name = "Ntshumayelo"; | ||
| let message = "My name is Ntshumayelo"; | ||
|
|
||
| console.log(message); | ||
| console.log(nameLength); | ||
|
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. The variable |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| const name = "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. The |
||
| let lengthName = name.length | ||
| let message = "my name is " + name.trim() + " and my name is " + lengthName + " characters long"; | ||
| console.log(message); | ||
| //console.log(name.trim); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,13 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| let numberOfStudents = 15 | ||
| let numberOfMentors = 8 | ||
| let totalNumberOfStudentsMentors = numberOfStudents + numberOfMentors; | ||
|
|
||
| let percentageOfStudents = numberOfStudents * 100 /totalNumberOfStudentsMentors; | ||
| percentageOfStudents = Math.round(percentageOfStudents); | ||
| console.log("Percentage of Students: " + percentageOfStudents + "%"); | ||
|
|
||
|
|
||
| let percentageOfMentors = numberOfMentors * 100 /totalNumberOfStudentsMentors; | ||
| percentageOfMentors = Math.round(percentageOfMentors); | ||
| console.log("Percentage of Mentors: " + percentageOfMentors + "%"); | ||
|
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. A great working solution and use of the For future reference, please stick to the ask. The expected result was something like this: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| function halve(number) { | ||
| let result = number / 2; | ||
| return result; | ||
| // complete the function here | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| let result = halve(12); | ||
|
|
||
| console.log(result); | ||
|
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. Well done! can be written like this, because when are returning a value after a calculation we dont need to give it a name, and we can just return it like below: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| function triple(number) { | ||
| return number * 3; | ||
| // complete function here | ||
| } | ||
|
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. Nice. |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| function multiply(num1, num2) { | ||
| let result = num1 * num2; | ||
| return result; | ||
|
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. FYI: see the above comment regarding the use of |
||
| // Calculate the result of the function and return it | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Declare your function first | ||
|
|
||
| function divide(num1, num2){ | ||
| let result = num1 / num2; | ||
| return result; | ||
| } | ||
| var result = divide(3, 4); | ||
|
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. FYI: |
||
|
|
||
| console.log(result); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Write your function here | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
| function createGreeting(name){ | ||
| let greeting = "Hello, My name is ${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. To display a variable within a string you need to use the backtick `` |
||
| return greeting; | ||
| } | ||
| let 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 sumNumbers(num1, num2){ | ||
| let result = num1 + num2; | ||
| return result; | ||
| } | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| let sum = sumNumbers(13,124) | ||
| console.log(sum); | ||
|
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. Well done. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Declare your function here | ||
|
|
||
| function createLongGreeting(name, age){ | ||
| let greeting = "Hello, my name is ${name} and I'm ${age} 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. See above the comment on using backtick when trying to insert a variable into a string |
||
| return greeting; | ||
| } | ||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,22 @@ var mentor2 = "Irina"; | |
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; | ||
|
|
||
| let mentor1 = "Daniel"; | ||
| let mentor2 = "Irina"; | ||
| let mentor3 = "Mimi"; | ||
| let mentor4 = "Rob"; | ||
| let mentor5 = "Yohannes"; | ||
|
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. While the use of |
||
|
|
||
| function spellName(name) { | ||
| return name.toUpperCase(); | ||
| } | ||
| function shoutyGreeting(name){ | ||
| let message = 'HELLO '+ spellName(name); | ||
| return message | ||
| }; | ||
| console.log(shoutyGreeting(mentor1)); | ||
| console.log(shoutyGreeting(mentor2)); | ||
| console.log(shoutyGreeting(mentor3)); | ||
| console.log(shoutyGreeting(mentor4)); | ||
| console.log(shoutyGreeting(mentor5)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| // There are syntax errors in this code - can you fix it to pass the tests? | ||
|
|
||
| function addNumbers(a b c) { | ||
| function addNumbers(a, b, c) { | ||
| return a + b + c; | ||
| } | ||
|
|
||
| function introduceMe(name, age) | ||
| return "Hello, my name is " + name "and I am " age + "years old"; | ||
| function introduceMe(name, age){ | ||
| return "Hello, my name is " + name + "and I am " + age + "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. Attention to detail is key with every program. The test will fail because there needs to be space as below: The rest of the code is perfect. |
||
| } | ||
|
|
||
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
| total = a + b; | ||
|
|
||
| return "The total is total"; | ||
| return "The total is " + total; | ||
| } | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| // The syntax for this function is valid but it has an error, find it and fix it. | ||
|
|
||
| function trimWord(word) { | ||
| return wordtrim(); | ||
| return word.trim(); | ||
| } | ||
|
|
||
| function getStringLength(word) { | ||
| return "word".length(); | ||
| return word.length; | ||
| } | ||
|
|
||
| function multiply(a, b, c) { | ||
| a * b * c; | ||
| return; | ||
| return a * b * c; | ||
|
|
||
| } | ||
|
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. Well done. |
||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| //returns a random number between 0 (inclusive) and 1 (exclusive) and multiplies with 10 | ||
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| } | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| // This function combines typed array with the new array. | ||
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| } | ||
|
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 is a third function for this exercise. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,10 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(priceOfProduct) { | ||
| let percentageOfProduct = (priceOfProduct) * 0.2; | ||
| return percentageOfProduct + (priceOfProduct); | ||
| } | ||
|
|
||
| /* | ||
| CURRENCY FORMATTING | ||
|
|
@@ -17,7 +20,10 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(num) { | ||
| let priceWithSalesTax = calculateSalesTax(num); | ||
| return "£" + priceWithSalesTax.toFixed(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. Well done. |
||
| =================================================== | ||
|
|
||
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.
Great work!