-
-
Notifications
You must be signed in to change notification settings - Fork 475
JavaScript week 1 #255
JavaScript week 1 #255
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 @@ | ||
| console.log("Hello world"); | ||
| console.log("Hayaaa"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `greeting` | ||
|
|
||
| let greeting= "hello"; | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| console.log(message); | ||
| let 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` | ||
| let greeting = "Hello, my name is "; | ||
| let firstName ="Maira"; | ||
| let fullGreeting = greeting + firstName; | ||
| console.log(fullGreeting); | ||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
| let firstName = "Maira"; | ||
| let nameLength = firstName.length | ||
|
|
||
| let message = "My name is " + firstName + " and my name is 5 characters long" | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| console.log(message); | ||
| let message = "My name is " + firstName + " and my name is 5 characters long"; | ||
| let result = message.trim(); | ||
| console.log(result); | ||
| // let text = " Hello World! "; | ||
| // let result = text.trim(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| let numberOfStudents = 50; | ||
| let numberOfMentors = 20; | ||
| let result = numberOfStudents + numberOfMentors; | ||
|
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. Use Therefore, here you can change all the |
||
| console.log(result); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| let total = numberOfStudents + numberOfMentors; | ||
| let percentageOfStudents = numberOfStudents * 100/ total; | ||
| let newPercentageOfStudents= Math.round(percentageOfStudents); | ||
| console.log(newPercentageOfStudents); | ||
| let percentageOfMentors = numberOfMentors * 100/ total; | ||
| let newPercentageOfMentors = Math.round(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. Again, you can use |
||
| console.log(newPercentageOfMentors); | ||
|
|
||
|
|
||
|
|
||
| // var preciseAge = 30.612437; | ||
| // var roughAge = Math.round(preciseAge); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
| 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. Correct spacing: |
||
| } | ||
|
|
||
| var result = halve(12); | ||
|
|
||
| console.log(result); | ||
|
|
||
|
|
||
| // function double(number) { | ||
| // return number * 2; | ||
| // } | ||
| // var result = double(2); | ||
|
|
||
| // console.log(result); // 4 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| return number * 3; | ||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
|
|
||
|
|
||
| // 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 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. Correct spacing: |
||
| } | ||
|
|
||
| // Assign the result of calling the function the variable `result` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| // Declare your function first | ||
| function divide (a,b){ | ||
| return 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. Correct spacing: |
||
| } | ||
|
|
||
| var result = divide(3, 4); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,20 @@ | ||
| // Write your function here | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
| function createGreeting (){ | ||
| let name = "Daniel" | ||
| let message = "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. Again, this format is better to use: |
||
| return message | ||
|
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. Indent |
||
| } | ||
|
|
||
| var greeting = createGreeting("Maira"); | ||
|
|
||
| console.log(greeting); | ||
|
|
||
| // let userName = 'John'; | ||
|
|
||
| // function showMessage() { | ||
| // let message = 'Hello, ' + userName; | ||
| // alert(message); | ||
| // } | ||
|
|
||
| // showMessage(); // Hello, John | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| // Declare your function first | ||
|
|
||
| // - Write a function that adds two numbers together | ||
| // - Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum` | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| let num1 = 13; | ||
| let num2 = 124; | ||
| function addNum (num1, num2){ | ||
| return num1+ num2; | ||
| } | ||
| console.log(sum); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| // Declare your function here | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| // Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) | ||
| // const greeting = createLongGreeting("Daniel", 30); | ||
| function createLongGreeting(name, age){ | ||
|
|
||
| return `Hello, my name is ${name} and I'm ${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. Great use of concat and interpolation overall, the best option |
||
| } | ||
| let greeting = createLongGreeting("Daniel", 30); | ||
| // let greeting = createLongGreeting("Maira", 32); | ||
| console.log(greeting); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| // Add comments to explain what this function does. You're meant to use Google! | ||
|
|
||
| // This function getting random number between 0(inclusive) and 1 (inclusive) sourse https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random | ||
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| } | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
|
|
||
| // this function combining 2 words by using concat method sourse https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_concat_string1 | ||
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| } | ||
|
|
||
| function concatenate(firstWord, secondWord, thirdWord) { | ||
| return 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. There is another way of doing this if you follow the link above |
||
| // 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,8 +5,17 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
| function calculateSalesTax() {} | ||
|
|
||
| function calculateSalesTax(price) { | ||
| let totalPrice = price * 0.2 + price; | ||
|
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. another way is return price * 1.2 |
||
| return totalPrice; | ||
| } | ||
| let totalPrice = calculateSalesTax(15); | ||
| console.log(totalPrice); | ||
| let totalPrice2 = calculateSalesTax(17.50); | ||
| console.log(totalPrice2); | ||
| let totalPrice3 = calculateSalesTax(34); | ||
| console.log(totalPrice3); | ||
|
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. We don't want to keep any debugging code in our tests. We should remove all the |
||
|
|
||
| /* | ||
| CURRENCY FORMATTING | ||
| =================== | ||
|
|
@@ -16,8 +25,20 @@ function calculateSalesTax() {} | |
|
|
||
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
| // Компания сообщила вам, что цены должны иметь 2 десятичных знака. | ||
| // Они также должны начинаться с символа валюты. | ||
| // Напишите функцию, которая добавляет налог к числу, а затем преобразует итоговую сумму в формат 0,00 фунтов стерлингов. | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| // Помните, что цены должны включать налог с продаж (подсказка: вы уже написали для этого функцию!) | ||
| function addTaxAndFormatCurrency(number) { | ||
| // let addTax = number + totalPrice; | ||
| // return `£${addTax}`; | ||
| let result = `£${calculateSalesTax(number).toFixed(2) }`; | ||
| return result | ||
| } | ||
| console.log( addTaxAndFormatCurrency(15) ) | ||
| console.log( addTaxAndFormatCurrency(17.50) ) | ||
| console.log( addTaxAndFormatCurrency(34) ) | ||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
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.
firstNamedoesn't exist here. You need to usenameinstead.5..trim()on the name to clear extra spacing around it.Like this: