-
-
Notifications
You must be signed in to change notification settings - Fork 475
London9-Elahe-Mortazavi-JavaScript-Core1-week1 #430
base: master
Are you sure you want to change the base?
Changes from all commits
ed1d823
6d954d7
7efcc4d
a6b1cbc
d29d0fa
39ec75a
3c850f9
66e298f
7c1f65f
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. give me your positive energy I need it to complete this course!"); | ||
|
|
||
| console.log(7); | ||
| console.log('I will make it'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `greeting` | ||
|
|
||
| var greeting = "hi Im elahe" | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||
| // Start by creating a variable `message` | ||||||
|
|
||||||
| var message = "anyone can help me with terminal?" | ||||||
| var messagetype = typeof message; | ||||||
|
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.
Suggested change
You can do this query right inside the console.log |
||||||
| console.log(message); | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| var greetingStart = "Hello, my name is "; | ||
| var name = "elahe"; | ||
| var message = greetingStart + name; | ||
|
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. Great! An even easier way to do this would be with template literals. Look in the example solution to find out what these are. |
||
| console.log(message); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
| var name = "Elahe"; | ||
| var nameLength = name.length; | ||
|
|
||
| console.log(message); | ||
| console.log(nameLength); | ||
| console.log() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,14 @@ | ||
| const name = " Daniel "; | ||
| var name = " Elahe"; | ||
| var nameLength = name.length; | ||
| console.log(nameLength); | ||
|
|
||
| let newString = (`my name is ${name} which includes ${nameLength} characters`); | ||
|
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. Oh here you are using template literals! Hurray. Let's prefer this way of putting code inside strings in general. |
||
| console.log(newString); | ||
|
|
||
|
|
||
| console.log(newString.trim()); | ||
| // why trim is not working here? | ||
|
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. It's because newString doesn't have whitespace either side of it. The extra whitespace is now inside the string. That is to say, when the variable |
||
|
|
||
| console.log(name.trim()); | ||
|
|
||
|
|
||
| console.log(message); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| let numberOfStudents = 70; | ||
| let numberOfTeachers = 20; | ||
| console.log(numberOfStudents+numberOfTeachers); | ||
|
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. 👍 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| var total = (numberOfStudents+numberOfMentors); | ||
| console.log(total); | ||
|
|
||
| let x = (numberOfStudents/total*100); | ||
| console.log(x); | ||
|
|
||
| let y = (numberOfMentors/total*100); | ||
| console.log(y); | ||
|
|
||
| console.log(Math.round(x)); | ||
| console.log(Math.round(y)); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number/2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
|
|
||
| console.log(result); | ||
|
|
||
| var result = halve(20); | ||
| console.log(result); | ||
|
|
||
| var result = halve(87); | ||
| console.log(result); | ||
| console.log(Math.round(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,4 +1,6 @@ | ||
| // Declare your function first | ||
| function divide(num1, num2){ | ||
| return num1/num2; | ||
| } | ||
|
|
||
| var result = divide(3, 4); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Write your function here | ||
|
|
||
| function createGreeting(name){ | ||
| return name; | ||
| } | ||
| var greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); | ||
| console.log(`hello my name is ${greeting}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Declare your function first | ||
|
|
||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); | ||
| function sum(num1, num2){ | ||
| return num1+num2; | ||
| } | ||
| console.log(sum(13, 124)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| var mentor1 = "Daniel"; | ||
| var mentor2 = "Irina"; | ||
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; | ||
| function greeting(name){ | ||
|
|
||
| return(`HELLO ${name}`); | ||
|
|
||
| } | ||
| console.log(greeting("daniel").toUpperCase()); | ||
| console.log(greeting("irina").toUpperCase()); | ||
| console.log(greeting("mimi").toUpperCase()); | ||
| console.log(greeting("rob").toUpperCase()); | ||
| console.log(greeting("yohannes").toUpperCase()); | ||
|
|
||
|
|
||
|
|
||
| let mentor1 = "Daniel"; | ||
| let mentor2 = "Irina"; | ||
| let mentor3 = "Mimi"; | ||
| let mentor4 = "Rob"; | ||
| let mentor5 = "Yohannes"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,28 @@ | ||
| // 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"; | ||
|
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. Fab! |
||
| } | ||
|
|
||
| function introduceMe(name, age) | ||
| return "Hello, my name is " + name "and I am " age + "years old"; | ||
|
|
||
|
|
||
|
|
||
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
| total = a + b; | ||
|
|
||
| return `The total is ${total}`; | ||
|
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. 👍 |
||
|
|
||
| return "The total is total"; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,18 +1,26 @@ | ||||||
| // 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(); | ||||||
|
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. 👍 |
||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| function getStringLength(word) { | ||||||
| return "word".length(); | ||||||
| return word.length; | ||||||
|
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. 🙌 |
||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| function multiply(a, b, c) { | ||||||
| a * b * c; | ||||||
| return; | ||||||
| let result = a * b * c; | ||||||
| return result; | ||||||
|
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. Yes, or even just
Suggested change
In this case we get no extra clarity from storing the expression in this result variable. Clarity is the goal! |
||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| /* | ||||||
| =================================================== | ||||||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,16 +2,21 @@ | |
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| } | ||
| // MATH.RANDOM : to find a random number between 0 to 1. so tofind a number between 0 to 100 we need to multiple it to 100. | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| } | ||
| } | ||
| // CONCAT: to mix arrays together we can use concat. the other way is spread operator. | ||
|
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. I understand what you are saying here and this answer is correct. 🥇 A clearer way to say it might be to say link or connect instead of mix. Mix implies the values might be "mixed up" / disordered in the new array, but they retain their original sequence order. CONCAT: to link arrays together we can use concat. the other way is spread operator. |
||
|
|
||
| function concatenate(firstWord, secondWord, thirdWord) { | ||
| return `${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. | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
| 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(num) { | ||
| return num * 1.2; | ||
|
|
||
| } | ||
|
|
||
| /* | ||
| CURRENCY FORMATTING | ||
|
|
@@ -17,7 +20,16 @@ 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 final = ((num * 1.2).toFixed(2)).toString(); | ||
|
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. I think this task is hinting for you to reuse the function you just wrote. Look up at calculateSalesTax. How can you use that function again here? How would using the function make this code clearer? I also think this variable name could be clearer. Why is naming variables clearly a great way to improve our code? |
||
| return `£${final}`; | ||
|
|
||
| } | ||
|
|
||
| // function completed | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
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.
👋 Hi Elahe!