-
-
Notifications
You must be signed in to change notification settings - Fork 475
NW5-Manchester-Mustafa Acar-JavaScript-Core-1-Coursework-Week1 #379
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,4 @@ | ||
| console.log("Hello world"); | ||
| console.log("Hello World. I just started learning JavaScript!"); | ||
| console.log(1); | ||
| console.log("Hello World. I just started learning JavaScript!"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `greeting` | ||
| let greeting = "Hello everyone, I am learning JavaScript"; | ||
|
|
||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| var message = "This is a string"; | ||
| var messageType = typeof message; | ||
|
|
||
| console.log(message); | ||
| console.log(messageType); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| console.log(message); | ||
| var greetingStart = "Hello, my name is "; | ||
| var firstName = "Mustafa."; | ||
|
|
||
| var greeting = greetingStart + firstName; | ||
|
|
||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| // Start by creating a variable `message` | ||
| var name = "Mustafa"; | ||
| var nameLength = name.length; | ||
| var message = | ||
| "Hello, my name is " + | ||
| name + | ||
| " and my name is " + | ||
| nameLength + | ||
| " characters long."; | ||
|
|
||
| console.log(nameLength); | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| const name = " Daniel "; | ||
| const firstName = " Daniel "; | ||
| let message = "Hello, my name is " + firstName.trim(); | ||
|
|
||
| console.log(firstName); | ||
|
|
||
| console.log(firstName.trim()); | ||
| 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 result=numberOfMentors+numberOfStudents; | ||
| console.log("Number of mentors: "+ numberOfMentors ) | ||
| console.log("Number of students: " + numberOfStudents) | ||
| console.log("Total number of students and mentors: "+ result) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| var result=numberOfMentors+numberOfStudents; | ||
|
|
||
| console.log("Total people in the class "+ result) | ||
|
|
||
| var percentageStudents=(numberOfStudents/result)*100; | ||
| var percentageMentors=(numberOfMentors/result)*100; | ||
|
|
||
| console.log("Percentage of mentors: " +percentageMentors) | ||
| console.log("Rounded percentage of mentors: " + Math.round(percentageMentors)) | ||
| console.log("Percentage of students: " + percentageStudents) | ||
| console.log("Rounded percentage of students: " + Math.round(percentageStudents)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number/2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
|
|
||
|
|
||
| console.log(result); | ||
| var result = halve(256); | ||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| return number*3; | ||
| } | ||
|
|
||
| var result = triple(12); | ||
| console.log(result); | ||
|
|
||
| var result = triple(11); | ||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| // Declare your function first | ||
| function divide(num1, num2) { | ||
| return num1 / num2; | ||
| } | ||
|
|
||
| var result = divide(3, 4); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // 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 total(num1, num2){ | ||
| return num1+num2; | ||
| } | ||
|
|
||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| let sum=total(13, 124) | ||
| console.log(sum); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| // Declare your function here | ||
| function createLongGreeting(name, age){ | ||
|
|
||
|
|
||
| return "Hello, my name is "+name+" and I'm "+age+" years old." | ||
|
|
||
| }// Declare your function here | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,16 @@ | ||
| // 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; | ||
| } | ||
|
Comment on lines
+4
to
13
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. Excellent work :) |
||
|
|
||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ function combine2Words(word1, word2) { | |
| } | ||
|
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. Could you add comments to explain the two functions above please? |
||
|
|
||
| function concatenate(firstWord, secondWord, thirdWord) { | ||
|
|
||
| return firstWord.concat(" ", 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. Good job |
||
| // 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,7 +5,9 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(productPrice) { | ||
| let productTax = (productPrice*20) / 100 + productPrice; | ||
|
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. Don't forget to indent. If you set up prettier and 'format on save' correctly, then this should happen automatically: https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/tree/master/exercises/A-setup-ide Let me know if you need any help with that 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'm not sure if you were introduced to 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 more of an advanced comment, but it's usually bad to have 'magic numbers' in code i.e. any numbers that don't have an obvious meaning. So I'd advise using an extra line to explain that the |
||
| return productTax;} | ||
|
|
||
| /* | ||
| CURRENCY FORMATTING | ||
|
|
@@ -17,7 +19,9 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(productPrice) { | ||
| return "£" + calculateSalesTax(productPrice).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. Nice :) |
||
| } | ||
|
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 Mustafa I checked your code nice job all of tests has passsed. I like to use this method for getting decimal points that we need. |
||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
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.
Excellent work :)