-
-
Notifications
You must be signed in to change notification settings - Fork 476
London 9 -Marziyeh Azhdari - JS-Core-1 - Week 1 #429
base: master
Are you sure you want to change the base?
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,6 @@ | ||
| console.log("Hello world"); | ||
| console.log("cd exercises/B-hello-world") | ||
| console.log(`This is my first coding week`) | ||
| console.log('Hello World. I just started learning JavaScript!') | ||
| console.log(29) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `greeting` | ||
| const 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` | ||
|
|
||
| console.log(message); | ||
| let message="This is a string" | ||
| let messageType = 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 first="Hello, my name is " | ||
| let myName="Mari" | ||
| let message=first+myName | ||
|
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 like how you concatenated the first+myName in the variable. I did it the very long way.... This is good. |
||
| console.log(message); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let myName="mari" | ||
| let lengthName=myName.length | ||
| let message="My name is "+myName+" and my name is " + lengthName+" characters long" | ||
| console.log(message); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| console.log(message); | ||
| let myName="mari" | ||
| let lengthName=myName.length | ||
| // let messageTwo=`my name is${myName}and my name is${lengthName}characters long` | ||
| let message=" My name is"+myName+" and my name is " + lengthName+" 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. This is a very small comment, but you should try to be consistent with your style. If you are putting spaces before and after the plus signs, for example.
Author
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 used 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. Thanks @mcarballopacheco Your suggestion is quite right. I'm practising consistency also. Javascript is soo hard for me |
||
| console.log(message.trim()); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| let numberOfStudents=15; | ||
| let numberOfMentors=8; | ||
| let total=numberOfMentors+numberOfStudents | ||
| console.log(numberOfStudents) | ||
| console.log(numberOfMentors) | ||
| console.log(total) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| let numberOfStudents = 15; | ||
| let numberOfMentors = 8; | ||
| let total=numberOfMentors+numberOfStudents | ||
| let percentageOfStudent=numberOfStudents/total*100; | ||
| console.log("Percentage students: "+Math.round(percentageOfStudent)+"%"); | ||
| let PercentageMentors=100-percentageOfStudent | ||
|
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 have also calculated the percentage of mentors, as.
Author
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 got it thanks. |
||
| console.log("Percentage mentors: "+Math.round(PercentageMentors)+"%"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number/2 | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| let result = halve(12); | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Declare your function first | ||
|
|
||
| function divide(num1,num2) { | ||
| return num1 / num2; | ||
| } | ||
| var result = divide(3, 4); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Write your function here | ||
| function greeting(name){ | ||
| console.log("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. I think here it would have make more sense based on the exercise to return the greeting and then use console.log() outside of the function.
Author
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 greeting(name){ Is it ok? |
||
| } | ||
| greeting("Daniel") | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Declare your function first | ||
|
|
||
| function sum(num1,num2){ | ||
| return num1+num2 | ||
| } | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); | ||
| console.log(sum(13,124)); | ||
|
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 will work, but in the exercise it mentioned to assign the value to a variable called sum, so: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Declare your function here | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
| function createLongGreeting(name,age){ | ||
| return "Hello ,my name is "+name+"and i'm "+age+ " years old" | ||
| } | ||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); |
| 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"; | ||
|
|
||
| const mentor1 = "Daniel"; | ||
| const mentor2 = "Irina"; | ||
| const mentor3 = "Mimi"; | ||
| const mentor4 = "Rob"; | ||
| const mentor5 = "Yohannes"; | ||
|
|
||
| function nameToUpperCase(name){ | ||
| return name.toUpperCase(); | ||
| } | ||
| function greeting(name){ | ||
| return `Hello ${nameToUpperCase(name)}`; | ||
| } | ||
| function result(name){ | ||
| return console.log(greeting(name)); | ||
| } | ||
| result(mentor1); | ||
|
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 looks great! |
||
| result(mentor3) | ||
| 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(price) { | ||
| return price*1.4 | ||
|
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 like this syntax...mine was sooo long... Great job. |
||
| } | ||
| console.log(convertToUSD(32)) | ||
| console.log(convertToUSD(50)) | ||
|
|
||
| /* | ||
| CURRENCY CONVERSION | ||
|
|
@@ -15,8 +19,11 @@ 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(price) { | ||
| return price*5.7*0.99 | ||
| } | ||
| console.log(convertToBRL(30)) | ||
| console.log(convertToBRL(1.5)) | ||
| /* ======= 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 |
|---|---|---|
|
|
@@ -16,21 +16,25 @@ | |
| the final result to the variable goodCode | ||
| */ | ||
|
|
||
| function add() { | ||
|
|
||
| function add(number1,number2) { | ||
| return number1+number2 | ||
| } | ||
| console.log(add(1,3)) | ||
|
|
||
| function multiply() { | ||
|
|
||
| function multiply(number1,number2) { | ||
| return number1*number2 | ||
| } | ||
| console.log(multiply(2,3)) | ||
|
|
||
| function format() { | ||
|
|
||
| function format(number) { | ||
| return `£${number}` | ||
| } | ||
| console.log(format(16)) | ||
|
|
||
| const startingValue = 2; | ||
|
|
||
| // Why can this code be seen as bad practice? Comment your answer. | ||
| //there are three functions that are not necessary and I think it is possible with a shorter code as well.(I am not sure!!!!!!!!!!!!!!!!!) | ||
| let badCode = | ||
|
|
||
|
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 is in general a bad idea to call many functions in the same line. It makes the code very hard to read. A better idea is to call each function once in a line and assign the result to a variable which then gets called in the following like but the next function, etc. |
||
| /* BETTER PRACTICE */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,24 @@ | ||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| //The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, | ||
| function getRandomNumber() { | ||
|
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 here, the question is asking what does the |
||
| return Math.random() * 10; | ||
| } | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| //The concat() method is used to merge two or more arrays or any number or string. This method does not change the existing arrays, but instead returns a new array.in this example with concat word1 and word2 coming next to gether. | ||
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| } | ||
|
|
||
| function concatenate(firstWord, secondWord, thirdWord) { | ||
| return firstWord.concat(" " + secondWord).concat(" " + thirdWord); | ||
| // return firstWord.concat(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. | ||
| } | ||
| // console.log(concatenate(code,your,future)) | ||
| // console.log(concatenate(I,like,pizza)) | ||
| // console.log(concatenate(I,am,13)) | ||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,12 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
| function calculateSalesTax() {} | ||
|
|
||
| function calculateSalesTax(price) { | ||
| return price*1.2 | ||
| } | ||
| console.log(calculateSalesTax(15)); | ||
| console.log(calculateSalesTax(17.50)); | ||
| console.log(calculateSalesTax(34)); | ||
| /* | ||
| CURRENCY FORMATTING | ||
| =================== | ||
|
|
@@ -17,8 +21,13 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(price) { | ||
| return `£${(price * 1.2).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. You should have used the calculateSalesTax function that you just created. The reason we create functions is to not repeat code which minimises errors. For example, let say the sales tax changes from 20% to 25%. if all of the times you calculated the sales tax you always use the calculateSalesTax function, then you only need to change the calculation in one place only. But if you are calculating in different places, then you would have to find them one by one. |
||
| } | ||
|
|
||
| console.log(addTaxAndFormatCurrency(15)) | ||
| console.log(addTaxAndFormatCurrency(17.5)) | ||
| console.log(addTaxAndFormatCurrency(34)) | ||
| /* | ||
| =================================================== | ||
| ======= 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.
Interesting test! I hope you realised that this will still just print "cd exercises/B-hello-world", even if this command has a very different meaning when you run it in the console, that is, this will not change directory when run inside the console.log as a string.