-
-
Notifications
You must be signed in to change notification settings - Fork 475
WM4_Dawit-Abraha_JavaScript_Core-1_Week-1 #323
Changes from all commits
09dcb6e
3956340
8479522
2a2e775
7b524f2
d354fff
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,7 @@ | ||
| console.log("Hello world"); | ||
| console.log("Hello world"); | ||
| // console.log(Hello); | ||
|
|
||
| var greeting = "Hello, I'm learning JavaScript"; | ||
| greeting = "Hello world"; | ||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| // Start by creating a variable `greeting` | ||
| var greeting; | ||
| greeting = "Hello World"; | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
|
|
||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
| var message = "This is a string"; | ||
|
|
||
| console.log(message); | ||
| console.log(typeof (message)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| var greetingStart = "Hello, my name is "; | ||
| var name = "Dawit"; | ||
| var message = greetingStart + name; | ||
| console.log(message); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| var name = "Dawit"; | ||
| var messageStart = "My name is"; | ||
| var messageMiddle = "and my name is"; | ||
| var messageEnd = "charactors long"; | ||
| var nameLength = name.nameLength; | ||
| var message = messageStart + " " + name + " " + messageMiddle + " " + name.length + " " + messageEnd; | ||
| console.log(message); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| var name = " Dawit "; | ||
| var messageStart = "My name is"; | ||
| var messageMiddle = "and my name is"; | ||
| var messageEnd = "characters long"; | ||
| var nameLength = name.nameLength; | ||
| var message = messageStart + " " + name.trim() + " " + messageMiddle + " " + name.length + " " + messageEnd; | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| var numberOfStudents = 15; | ||
| var student = "Number of students: "; | ||
| var numberOfMentors = 8; | ||
| var mentors = "Number of mentors: "; | ||
|
|
||
| var total = numberOfStudents + numberOfMentors; | ||
| var totalOfAll = "Total number of students and mentors: "; | ||
|
|
||
| console.log(student + numberOfStudents); | ||
| console.log(mentors + numberOfMentors); | ||
| console.log(totalOfAll + total); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| let total = numberOfStudents + numberOfMentors | ||
| let studentsPercentage = numberOfStudents / total * 100 | ||
| console.log(Math.round(studentsPercentage) + "%") | ||
| let mentorsPercentage = (numberOfMentors * 100) / total | ||
| console.log(Math.round(mentorsPercentage) + "%") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| function halve(number) { | ||
| var number = 12; | ||
| // complete the function here | ||
| return number - (number / 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. nice way to define halve number - (number / 2) you can also just divide the |
||
| } | ||
|
|
||
| var result = halve(12); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| var number = 12; | ||
|
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. I think you don't need write step 3 (var number = 12;) as passed "number" as parameter in the function. |
||
| return number = (number * 3); | ||
|
|
||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| console.log(result); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| function multiply(a, b) { | ||
| // Calculate the result of the function and return it | ||
| return result = a * b; | ||
| } | ||
|
|
||
| // Assign the result of calling the function the variable `result` | ||
| var 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(a, b) { | ||
| return result = a / b; | ||
| } | ||
|
|
||
| var result = divide(3, 4); | ||
| var result = divide(1.5, 2); | ||
|
|
||
| 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 greeting = `Hello, my name is ${name}` | ||
| } | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
| var greeting = createGreeting("Dawit"); | ||
|
|
||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| // Declare your function first | ||
| function passing(a, b) { | ||
| return sum = a + b; | ||
| } | ||
|
|
||
| // Call the function and assign to a variable `sum` | ||
| var sum = passing(13, 124) | ||
|
|
||
| console.log(sum); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Declare your function here | ||
| function createLongGreeting(name, age) { | ||
| return greeting = "Hello, my name is " + name + "and my age is " + age + "years old"; | ||
| } | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,16 +2,24 @@ | |||||
| function getRandomNumber() { | ||||||
| return Math.random() * 10; | ||||||
| } | ||||||
|
|
||||||
| //* | ||||||
| // The random() method returns a random value that is greater than or equal to 0.0 and less than 1.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. Nice explanation! |
||||||
| //* | ||||||
| // Add comments to explain what this function does. You're meant to use Google! | ||||||
| function combine2Words(word1, word2) { | ||||||
| return word1.concat(word2); | ||||||
| } | ||||||
| //* | ||||||
| // This function will join the two words without space between them. | ||||||
|
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.
Suggested change
|
||||||
| //* | ||||||
|
|
||||||
| function concatenate(firstWord, secondWord, thirdWord) { | ||||||
| // Write the body of this function to concatenate three words together. | ||||||
| // Look at the test case below to understand what this function is expected to return. | ||||||
| return firstWord.concat(" ", secondWord).concat(" ", thirdWord); | ||||||
|
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. I like the way you've called |
||||||
| } | ||||||
|
|
||||||
| console.log(concatenate("Code", "Your","Future")); | ||||||
|
|
||||||
| /* | ||||||
| =================================================== | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,11 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(price) { | ||
| let salesTax = (price * 20) / 100; | ||
|
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 confused me to begin with as to why you were multiplying the price by 20. One of the reasons is that I have no idea what the significance of that number is. In the industry we'd refer to this as a "magic number". It's considered better to treat it as a named constant defined somewhere in your code. Some people/organisations will capitalize shared constants, something like: |
||
| let totalPrice = price + salesTax; | ||
| return totalPrice; | ||
| } | ||
|
|
||
| /* | ||
| CURRENCY FORMATTING | ||
|
|
@@ -17,8 +21,13 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
|
|
||
| function addTaxAndFormatCurrency(amount) { | ||
| // const total = calculateSalesTax(amount); | ||
| // const formattedTotal = `£${total.toFixed(2)}`; | ||
| // return formattedTotal; | ||
| return `£${calculateSalesTax(amount).toFixed(2)}`; | ||
| } | ||
| console.log(addTaxAndFormatCurrency(17.5)); | ||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
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.
I am not clear what do yo mean by nameLength = name.nameLength? where did you already declared nameLength
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.
I appreciate the comments. I'll make it right.