-
-
Notifications
You must be signed in to change notification settings - Fork 475
London Class_8 - Deago Browne - JS - Week_1 #244
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); | ||
|
|
||
| console.log (7); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `greeting` | ||
| var greeting = "Meow"; | ||
| 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` | ||
|
|
||
| console.log(message); | ||
| var message = "Meow"; | ||
| var messageType = typeof message; | ||
| console.log(messageType); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| var start = "Hi, name's"; | ||
| var myName = "Deago"; | ||
| var message = start + myName; | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
| var myName = "Deago"; | ||
| var nameLength =`My name is Deago, and my name is ${myName.length} characters long`; | ||
|
|
||
| console.log(message); | ||
| console.log(nameLength); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| const name = " Deago "; | ||
| nameLength = name.length | ||
| var message = `My name is ${name.trim()} and my name is ${name.trim().length} characters long` | ||
|
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 could store the 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 need to use semicolom |
||
| 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 = 15; | ||
| let numberOfMentors = 8; | ||
| let total = numberOfStudents + numberOfMentors; | ||
|
|
||
| console.log(numberOfStudents) | ||
| console.log(numberOfMentors) | ||
| console.log(total) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,13 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| var total = numberOfStudents + numberOfMentors; | ||
|
|
||
| var perStu = (numberOfStudents / total) * 100; | ||
|
|
||
| var perMen = (numberOfMentors / total) * 100; | ||
|
|
||
| var perMenTo = Math.round(perMen)+"%"; | ||
| var perStuTo = Math.round(perStu)+"%"; | ||
|
|
||
| console.log(perMenTo, perStuTo) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return 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.
|
||
| } | ||
|
|
||
| var result = halve(12); | ||
| var result = halve(512); | ||
|
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.
|
||
|
|
||
| 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 | ||
|
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.
|
||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| // Calculate the result of the function and return it | ||
| function multiply( a, b) { | ||
|
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 a * b | ||
| } | ||
|
|
||
| // Assign the result of calling the function the variable `result` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| // Declare your function first | ||
| function divide(a, b) { | ||
| return a / b; | ||
| } | ||
|
|
||
| var result = divide(3, 4); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| // Write your function here | ||
| function createGreeting (a) { | ||
| return "Hello, my name is " + a | ||
|
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 better to use this format in general. |
||
| } | ||
|
|
||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| // Declare your function first | ||
| function add(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| // Call the function and assign to a variable `sum` | ||
| var sum = add(13, 124); | ||
|
|
||
|
|
||
| console.log(sum); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| // Declare your function here | ||
|
|
||
| function createLongGreeting(a, b) { | ||
| return "Hello, my name is " + a + " and I am " | ||
| + b + " years old"; | ||
| } | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,18 @@ var mentor2 = "Irina"; | |
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; | ||
|
|
||
| function names (b) { | ||
| return b.toUpperCase(); | ||
| } | ||
|
|
||
| function message (b) { | ||
|
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.
|
||
| var name = names(b); | ||
| return "HELLO " + name; | ||
| } | ||
|
|
||
| console.log(message(mentor1)); | ||
| console.log(message(mentor2)); | ||
| console.log(message(mentor3)); | ||
| console.log(message(mentor4)); | ||
| console.log(message(mentor5)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,19 @@ | ||
| // 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"; | ||
| var name = "Sonjide"; | ||
|
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 not needed in the test. |
||
|
|
||
| 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"; | ||
| return "The total is " + total; | ||
| } | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| // 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(); | ||
| var sentence = "A wild sentence appeared!"; | ||
| var word = "Turtles"; | ||
|
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. Your variable is declared correctly. I would recommend using let instead. Because if you work with someone else on a very big piece of code, another person might come up with the same variable name word and without knowing rewrite yours. It will then can then cause a problem. |
||
|
|
||
| function getStringLength(word, sentence) { | ||
| return (sentence, 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. I think there is an extra ; |
||
| } | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| // returns a random number between 1 <1, then multiplies that number by 10 | ||
|
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. Hi Deago, I think there is a typo. Did you mean from 0 to < 1? |
||
| } | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| // creates a new array consisting of all elements within the object | ||
| } | ||
|
|
||
| function concatenate(firstWord, secondWord, 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. No new line needed at the begining of the function. |
||
| 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 |
|---|---|---|
|
|
@@ -17,8 +17,12 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
|
|
||
|
|
||
|
|
||
| function addTaxAndFormatCurrency(x) { | ||
| return (x + 0.20*x).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. Hi Deago, well done for fixing it. If you want to add a pound sign, think of it as a "string" that you add with + in your return formula. 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 can be rewritten like this: |
||
| } | ||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // let num = 30; | ||
|
|
||
| // let fee; | ||
|
|
||
| // fee = (1/100) * num; | ||
|
|
||
| // let total; | ||
|
|
||
| // total = num - fee; | ||
|
|
||
| // console.log(total); | ||
|
|
||
| function convertToBRL(num) { | ||
| let brl = 5.7; | ||
| let result; | ||
| let fee; | ||
| fee = (1/100) * num; | ||
| result = (num - fee) * brl; | ||
| return result.toFixed(2); | ||
| } | ||
|
|
||
| console.log(convertToBRL(30)); |
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 use of concatinating string here ⭐
var->const(orletif the value changes)