-
-
Notifications
You must be signed in to change notification settings - Fork 475
London 9 olus odude js1 wk1 #413
base: master
Are you sure you want to change the base?
Changes from all commits
5721a57
ba3ade9
2a8b19c
7437ea2
c336288
7fde69f
ec298c3
ca8264c
4c6b722
69f6adb
fdbd2f0
5df43b7
deacb9f
6765c36
0b0c429
343e6ce
2d471f9
87dc4a0
40be8d3
72c0c89
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,3 @@ | ||
| console.log("Hello world"); | ||
| console.log("Hello world", "hellos"); | ||
| console.log(5, 5); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `greeting` | ||
|
|
||
| let greeting = "Hello World"; | ||
| 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` | ||
|
|
||
| let message = "good morning"; | ||
| let stringType = typeof message; | ||
| console.log(message); | ||
| console.log(messageType); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let greeting = "Hello my name is"; | ||
| let name = "olus"; | ||
| let message = greeting + " " + name; | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let name = "olus" | ||
| let nameLength = name.length; | ||
| let message = `my name is ${name} and my name is ${nameLength} long`; | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| let pName = name.trim(); | ||
| let messgae = `my name is ${pName} and my name is ${pName.length} characters long`; | ||
| 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 = 15 | ||
| let numberOfMentors = 8 | ||
| let message = ` Total number of students and mentors: ${numberOfStudents + numberOfMentors}`; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| let numberOfStudents = 15; | ||
| let numberOfMentors = 8; | ||
| let sum = (numberOfStudents + numberOfMentors); | ||
|
|
||
| let percentage = function percent(val, total){ | ||
| return (Math.round(val / total) * 100 ); | ||
| } | ||
|
|
||
| let perOfStud = percentage(numberOfStudents, sum); | ||
| let perOfMent = percentage(numberOfMentors, sum); | ||
| console.log(`Percentage students: ${perOfStud}`); | ||
| console.log(`Percentage Mentors: ${perOfMent}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number / 2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
|
|
||
| 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,4 +1,7 @@ | ||
| // 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,5 +1,9 @@ | ||
| // Write your function here | ||
|
|
||
| function createGreeting(name){ | ||
| return `Hello, my name is ${name}` | ||
| } | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Declare your function first | ||
|
|
||
| function addNumb( a, b ){ | ||
| return a + b; | ||
| } | ||
| let sum = addNumb(13, 124); | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,11 @@ | |
| Write a function that converts a price to USD (exchange rate is 1.4 $ to £) | ||
| */ | ||
|
|
||
| function convertToUSD() {} | ||
| function convertToUSD(pound) { | ||
| let dollar = pound * 1.4; | ||
| console.log(dollar); | ||
| return dollar; | ||
| } | ||
|
|
||
| /* | ||
| CURRENCY CONVERSION | ||
|
|
@@ -15,8 +19,16 @@ function convertToUSD() {} | |
| They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. | ||
| */ | ||
|
|
||
| function convertToBRL() {} | ||
| function convertToBRL(pound) { | ||
| let bRail = pound * 5.7; | ||
| console.log(bRail); | ||
| let railAndFee = bRail * 0.99; | ||
| console.log(railAndFee); | ||
|
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. Hint: when you have multiple This works because |
||
| return railAndFee.toFixed(2) * 1; | ||
| } | ||
|
|
||
| console.log(convertToBRL(30)); | ||
| console.log(convertToUSD(32)); | ||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| There are some Tests in this file that will help you work out if your code is working. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| // 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"; | ||
| function introduceMe(name, age) { | ||
| return "Hello, my name is " + `${name}` + " and I am " + `${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. This works, but is a bit convoluted :) I think the idea was to add the missing |
||
|
|
||
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
| total = 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. use |
||
|
|
||
| return "The total is total"; | ||
| return `The total is ${total}`; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -30,9 +31,7 @@ test("addNumbers adds numbers correctly", () => { | |
| }); | ||
|
|
||
| test("introduceMe function returns the correct string", () => { | ||
| expect(introduceMe("Sonjide", 27)).toEqual( | ||
| "Hello, my name is Sonjide and I am 27 years old" | ||
| ); | ||
| expect(introduceMe("Sonjide", 27)).toEqual("Hello, my name is Sonjide and I am 27 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. why has this changed? |
||
| }); | ||
|
|
||
| test("getTotal returns a string describing the total", () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,15 @@ | ||
| // 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(); | ||
| return word.length; | ||
| } | ||
|
|
||
| function multiply(a, b, c) { | ||
| a * b * c; | ||
| return; | ||
| return a * b * c; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -29,9 +28,7 @@ test("trimWord trims leading and trailing whitespace", () => { | |
| }); | ||
|
|
||
| test("trimWord doesn't remove whitespace in the middle of the string", () => { | ||
| expect(trimWord(" CodeYourFuture teaches coding ")).toEqual( | ||
| "CodeYourFuture teaches coding" | ||
| ); | ||
| expect(trimWord(" CodeYourFuture teaches coding ")).toEqual("CodeYourFuture teaches coding"); | ||
|
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. why this change? |
||
| }); | ||
|
|
||
| test("getStringLength returns the length of a word", () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,38 @@ | ||
| // Add comments to explain what this function does. You're meant to use Google! | ||
|
|
||
| // the function generates a random number between 0 and <1, | ||
| //the number is never equal to 1. times the nubmeer by 10 | ||
| //creates a random numbere between 0 and <10. | ||
| /* | ||
| google say : The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range | ||
|
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. Not google :) Mozilla Developer Network - the best reference |
||
|
|
||
| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#:~:text=The%20Math.random()%20function,scale%20to%20your%20desired%20range. | ||
| */ | ||
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| } | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
|
|
||
| /* | ||
| the below function joins two words together as is, so if thier is no white space the words will be read as one. | ||
|
|
||
| google= The concat() function concatenates the string arguments to the calling string and returns a new string. Changes to the original string or .. | ||
|
|
||
| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat | ||
| */ | ||
|
|
||
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| } | ||
|
|
||
| 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("I", "am", 13)); | ||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,29 @@ | |
| A business requires a program that calculates how much the price of a product is including sales tax | ||
| Sales tax is 20% of the price of the product. | ||
| */ | ||
| /* | ||
| // function does decimaal conversion and tax | ||
| function calculateSalesTax(price) { | ||
| //convert number to decimall place twin | ||
| let newPrice = price.toFixed(2); | ||
| //convert numb form string back to numb | ||
| let usePrice = newPrice * 1; | ||
| console.log(typeof usePrice); | ||
| console.log(usePrice); | ||
| let taxPrice = usePrice * 1.2; | ||
| let showPrice = taxPrice.toFixed(2); | ||
| console.log(showPrice); | ||
| return `£ ${showPrice}`; | ||
| } | ||
| calculateSalesTax(15); | ||
| */ | ||
|
Comment on lines
+7
to
+22
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. Remove |
||
|
|
||
| function calculateSalesTax() {} | ||
|
|
||
| function calculateSalesTax(price) { | ||
| let taxPrice = price * 1.2; | ||
| console.log(taxPrice); | ||
| return taxPrice; | ||
| } | ||
| calculateSalesTax(34); | ||
| /* | ||
| CURRENCY FORMATTING | ||
| =================== | ||
|
|
@@ -17,8 +37,14 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(price_tax) { | ||
| let newPrice = calculateSalesTax(price_tax); | ||
| let showPrice = newPrice.toFixed(2); | ||
| console.log(showPrice); | ||
| return `£${showPrice}`; | ||
| } | ||
|
|
||
| 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.
Small detail: the variable's value doesn't change, so you might as well use
const, just so it becomes a habit.