-
-
Notifications
You must be signed in to change notification settings - Fork 475
LONDON CLASS_8 - RAHWA GHEBREMICHAEL - MODULE - JS1 WEEK_1 #252
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,22 @@ | ||
|
|
||
|
|
||
| //console.log(Hello world) | ||
| console.log("Hello world"); | ||
|
|
||
| //Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!' | ||
| console.log("Hello World. I just started learning JavaScript!"); | ||
|
|
||
|
|
||
| //What happens when you console.log() just a number without quotes? | ||
| //Terminal prints out a number. | ||
| console.log(80); | ||
|
|
||
|
|
||
| //Try to console.log() several things at once. | ||
| //Terminal prints out everything in one line. | ||
| console.log("I bought a shoes for £80", "Hello world", "I am curious to learn JS"); | ||
|
|
||
|
|
||
| //What happens when you get rid of the quote marks? | ||
| //Terminal shows a syntax error. | ||
| console.log(I am curious to learn JS); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| // Start by creating a variable `greeting` | ||
| //Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log | ||
| let greeting="Hello world!"; | ||
|
|
||
| //Print your `greeting` to the console 3 times | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| console.log(message); | ||
| //Write a program that logs a message and its type | ||
| const number = 4; | ||
| let message = "Rahwa"; | ||
| let text; | ||
| //Terminal shows a number | ||
| console.log(typeof number); | ||
|
|
||
| //Terminal shows a string | ||
| console.log(typeof message); | ||
|
|
||
| //Terminal shows undefined | ||
| console.log(typeof text); | ||
|
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 also need to output the variables too not just their type. In the example, they missed it too. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `message` | ||
| //Write a program that logs a message with a greeting and your name | ||
| let startGreeting = "Hi, my name is "; | ||
| let nameOfPerson="Rahwa"; | ||
| let message = startGreeting + nameOfPerson; | ||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| // Start by creating a variable `message` | ||
| //Log a message that includes the length of your name | ||
| let nameOfPerson = "Rahwa"; | ||
| let nameOfPersonLength = nameOfPerson.length; | ||
| let message = `My name is ${nameOfPerson} and my name is ${nameOfPersonLength} character long.`; | ||
|
|
||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| //Log the same message using the variable, `name` provided | ||
| //Use the `.trim` method to remove the extra whitespace | ||
| const nameOfPerson = " Daniel "; | ||
| let message = nameOfPerson.trim(); | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,11 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
|
|
||
| //Create two variables `numberOfStudents` and `numberOfMentors` | ||
|
|
||
| let numberOfStudents = 15; | ||
| let numberOfMentors = 8; | ||
| let sum = numberOfStudents + numberOfMentors; | ||
|
|
||
| //Log a message that displays the total number of students and mentors | ||
|
|
||
| console.log(`The total number of students and mentors is ${sum}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
|
|
||
| //Using the variables provided in the exercise calculate the percentage of mentors and students in the group | ||
|
|
||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| var total = numberOfStudents + numberOfMentors; | ||
| var percentageOfStudents = (Math.round(numberOfStudents/total * 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. The outer |
||
| var percentageOfMentors = (Math.round(numberOfMentors / total * 100)); | ||
|
|
||
|
|
||
| console.log (`percentage students:${percentageOfStudents}%`); | ||
| console.log(`percentage mentors:${percentageOfMentors}%`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
|
|
||
| //Complete the function in exercise.js so that it halves the input | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number/2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| //Try calling the function more than once with some different numbers | ||
| let resultOne = halve(12); | ||
| let resultTwo = halve(50); | ||
| let resultThree = halve(125); | ||
|
|
||
| console.log(resultOne); | ||
| console.log(resultTwo); | ||
| console.log(resultThree); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
|
|
||
| //Complete the function in exercise2.js so that it triples the input | ||
|
|
||
| function triple(number) { | ||
| // complete function here | ||
|
|
||
| return number * 3; | ||
| } | ||
| let resultOne = triple(12); | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| console.log(result); | ||
| console.log(resultOne); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| // 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; | ||
| } | ||
|
|
||
| // Assign the result of calling the function the variable `result` | ||
| var result = multiply(3, 4); | ||
| let result = multiply(3, 4); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Declare your function first | ||
|
|
||
| var result = divide(3, 4); | ||
| function divide(a, b){ | ||
| return a/b; | ||
| } | ||
| let result = divide(3, 4); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Write your function here | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
| function creatGreeting(nameOfPerson){ | ||
| return `Hello, my name is ${nameOfPerson}`; | ||
|
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. Indentations and spacing should be like this: |
||
| } | ||
| //calling the function | ||
| let greeting = creatGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| // 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` | ||
| function sum(a, b){ | ||
| return a + b; | ||
| } | ||
| // Call the function and assign to a variable `sum` | ||
| let total = sum(13, 124); | ||
|
|
||
| console.log(sum); | ||
| console.log(total); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // 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) | ||
| function nameAndAge(name, age){ | ||
| return `My name is ${name} and I am ${age} years old.`; | ||
| } | ||
| const longGreeting = nameAndAge("Daniel", 30); | ||
|
|
||
| console.log(greeting); | ||
| console.log(longGreeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,22 @@ | ||
| var mentor1 = "Daniel"; | ||
| var mentor2 = "Irina"; | ||
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; | ||
|
|
||
| //Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting. | ||
| //Log each greeting to the console. | ||
|
|
||
| // let mentor1 = "Daniel"; | ||
| // let mentor2 = "Irina"; | ||
| // let mentor3 = "Mimi"; | ||
| // let mentor4 = "Rob"; | ||
| // let mentor5 = "Yohannes"; | ||
| function upperCase(greeting, nameOfPerson){ | ||
|
|
||
| let text = `${greeting.toUpperCase()} ${nameOfPerson.toUpperCase()}`; | ||
| return text; | ||
|
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. All the content of the function need to be indented forward. |
||
| } | ||
|
|
||
| console.log(upperCase("Hi", "Daniel")); | ||
| console.log(upperCase("Hi", "Irina")); | ||
| console.log(upperCase("Hi", "Mimi")); | ||
| console.log(upperCase("Hi", "Rob")); | ||
| console.log(upperCase("Hi", "Yohannes")); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,25 @@ | ||
| // There are syntax errors in this code - can you fix it to pass the tests? | ||
|
|
||
| function addNumbers(a b c) { | ||
| //addNumbers adds numbers correctly | ||
| function addNumbers(a, b, c) { | ||
| return a + b + c; | ||
| } | ||
| console.log(addNumbers(3, 4, 6)); | ||
|
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. In the test, we don't want to leave any debugging content. |
||
|
|
||
| //introduceMe function returns the correct string | ||
| function introduceMe(name, age) | ||
| return "Hello, my name is " + name "and I am " age + "years old"; | ||
|
|
||
| { | ||
| let message = `Hello, my name is ${name} and I am ${age} years old`; | ||
| 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.
|
||
| console.log(introduceMe("Sonjide", 27)); | ||
|
|
||
| //getTotal returns a string describing the total | ||
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
|
|
||
| return "The total is total"; | ||
| let total = a + b; | ||
| return "The total is " + total ; | ||
| } | ||
|
|
||
| console.log(getTotal(23, 5)) | ||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,40 @@ | ||
| // The syntax for this function is valid but it has an error, find it and fix it. | ||
|
|
||
| //trimWord trims leading and trailing whitespace | ||
| function trimWord(word) { | ||
| return wordtrim(); | ||
| return word.trim(); | ||
| } | ||
| // console.log(trimWord("CodeYourFuture ")); | ||
|
|
||
| function getStringLength(word) { | ||
| return "word".length(); | ||
| // //trimWord doesn't remove whitespace in the middle of the string | ||
| // function trimSentence(sentence) { | ||
| // return sentence.trim(); | ||
| // } | ||
| // console.log(trimSentence(" CodeYourFuture teaches coding ")); | ||
|
|
||
| //getStringLength returns the length of a word | ||
| function getStringLength(word) { | ||
| return word.length; | ||
| } | ||
| // console.log(getStringLength("Turtles")); | ||
|
|
||
| // //getStringLength returns the length of a sentence | ||
| // function getStringLength(sentence) { | ||
| // return sentence.length; | ||
| // } | ||
| // console.log(getStringLength("A wild sentence appeared!")); | ||
|
|
||
| function multiply(a, b, c) { | ||
| a * b * c; | ||
| return; | ||
| //multiply multiplies numbers | ||
| function multiply(a, b, c) { | ||
| 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. Indent |
||
| } | ||
| // console.log(multiply(2, 3, 6)); | ||
|
|
||
| //multiply multiplies different numbers | ||
| // function multiply(a, b, c) { | ||
| // return a * b * c; | ||
| // } | ||
| // console.log(multiply(2, 3, 4)); | ||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,23 @@ | ||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| //return Math.random() * 10 - It returns a random number between 0 and 9 where 0 and 9 are included. | ||
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| } | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| //return word1.concat(word2) - Joins word1 and word2. | ||
| function combine2Words(word1, word2) { | ||
|
|
||
| return word1.concat(word2); | ||
| } | ||
|
|
||
| //Join firstWord, secondWord and thirdWord. | ||
| 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, " ", thirdWord); | ||
| } | ||
|
|
||
| console.log(concatenate("code", "your", "future")); | ||
|
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, no |
||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,14 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(priceOfProduct) { | ||
| let priceProductTax = priceOfProduct + (priceOfProduct * 20) / 100; | ||
| return priceProductTax; | ||
| } | ||
|
|
||
| console.log(calculateSalesTax(15)); | ||
| console.log(calculateSalesTax(17.50)); | ||
| console.log(calculateSalesTax(34)); | ||
|
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, no |
||
| /* | ||
| CURRENCY FORMATTING | ||
| =================== | ||
|
|
@@ -17,7 +23,17 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
|
|
||
| function addTaxAndFormatCurrency(calculateSalesTax) { | ||
| let priceProductTax = calculateSalesTax + (calculateSalesTax * 20) / 100; | ||
| let taxFormat = `£${priceProductTax.toFixed(2)}`; | ||
| return taxFormat; | ||
| } | ||
| console.log(addTaxAndFormatCurrency(15)); | ||
| console.log(addTaxAndFormatCurrency(17.5)); | ||
| console.log(addTaxAndFormatCurrency(34)); | ||
|
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, no |
||
|
|
||
|
|
||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| "description": "Exercises for JS1 Week 1", | ||
| "license": "CC-BY-SA-4.0", | ||
| "scripts": { | ||
| "test": "jest" | ||
| "test": "jest","extra-tests":"jest extra" | ||
|
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 don't need to change this file. |
||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
|
|
||
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.
We use
constif the content of the variable will not change, and if it changes we uselet. So in this case all of them should have beenconst.