-
-
Notifications
You must be signed in to change notification settings - Fork 475
ZA2_Nishka-Kisten-JavaScript-Core-1-Coursework-Week1 #293
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("Nishka Kisten"); | ||
| console.log(23); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `greeting` | ||
|
|
||
| var 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` | ||
|
|
||
| var message = "This is a string"; | ||
|
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. Very neat code here. Keep that up! |
||
| var 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` | ||
|
|
||
| var greetingStart ="Hello, my name is "; | ||
| var name = "Daniel"; | ||
| var message= greetingStart + name; | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| var name= "Nishka"; | ||
| var nameLength = name.length; | ||
| var message = "My name is " + name + " and my name is " + nameLength + " 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); | ||
| var nameLength = name.length; | ||
| var message = "My name is" + name +" and my name is " + nameLength + " characters long"; | ||
| var messageTrim = message.trim(); | ||
| console.log(messageTrim); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| var studentsAndMentors = numberOfStudents + numberOfMentors; | ||
|
|
||
| var messageStudents = "Number of students: " + numberOfStudents; | ||
|
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 great javascript basics. You understanding the basic concept to declaring variables and assigning arguments to them. Well done! |
||
| var messageMentors = "Number of mentors: " + numberOfMentors; | ||
| var messageBoth = "Total number of students and mentors: " + studentsAndMentors; | ||
|
|
||
| console.log(messageStudents); | ||
| console.log(messageMentors); | ||
| console.log(messageBoth); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,15 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| var numberOfBoth = numberOfStudents + numberOfMentors; | ||
|
|
||
| var percentageOfStudents = (numberOfStudents / numberOfBoth)* 100; | ||
| var percentageOfMentors = (numberOfMentors / numberOfBoth)* 100; | ||
|
|
||
| var percentageRoundStudents = Math.round(percentageOfStudents); | ||
| var percentageRoundMentors = Math.round(percentageOfMentors); | ||
| var messageStudents = "Percentage students: " + percentageRoundStudents +"%"; | ||
| var messageMentors = "Percentage mentors: " + percentageRoundMentors +"%"; | ||
|
|
||
| console.log(messageStudents); | ||
| console.log(messageMentors); | ||
|
|
| 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); | ||
| var result = halve(30); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| return number * 3 | ||
| } | ||
|
|
||
| var result = triple(12); | ||
| var result = triple(50); | ||
|
|
||
| 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,7 @@ | ||
| // Declare your function first | ||
| function add(num1, num2){ | ||
| return num1 + num2; | ||
| } | ||
|
|
||
| // Call the function and assign to a variable `sum` | ||
| var sum = add(13, 124); | ||
|
|
||
| console.log(sum); |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,3 +3,37 @@ var mentor2 = "Irina"; | |||||||||||
| var mentor3 = "Mimi"; | ||||||||||||
| var mentor4 = "Rob"; | ||||||||||||
| var mentor5 = "Yohannes"; | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| var mentor1 = "Daniel"; | ||||||||||||
| var mentor2 = "Irina"; | ||||||||||||
| var mentor3 = "Mimi"; | ||||||||||||
| var mentor4 = "Rob"; | ||||||||||||
| var mentor5 = "Yohannes"; | ||||||||||||
|
|
||||||||||||
| function capitalize(name) { | ||||||||||||
| return name.toUpperCase(); | ||||||||||||
| } | ||||||||||||
| // var result = capitalize(mentor1); | ||||||||||||
| // console.log(result); | ||||||||||||
| var shoutyMessage = "hello" | ||||||||||||
|
|
||||||||||||
| function greeting(string){ | ||||||||||||
| return string.toUpperCase(); | ||||||||||||
|
|
||||||||||||
| } | ||||||||||||
| // var result2 = greeting(shoutyMessage); | ||||||||||||
|
|
||||||||||||
| // console.log(result2); | ||||||||||||
|
|
||||||||||||
| function shoutyGreeting(name, string){ | ||||||||||||
|
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. Well done Nishka 💯
Suggested change
|
||||||||||||
| return greeting(string) + " " + capitalize(name); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| console.log(shoutyGreeting(mentor1, shoutyMessage)); | ||||||||||||
| console.log(shoutyGreeting(mentor2, shoutyMessage)); | ||||||||||||
| console.log(shoutyGreeting(mentor3, shoutyMessage)); | ||||||||||||
| console.log(shoutyGreeting(mentor4, shoutyMessage)); | ||||||||||||
| console.log(shoutyGreeting(mentor5, shoutyMessage)); | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,19 @@ | ||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| function getRandomNumber() { | ||
| return Math.random() * 10; | ||
| return Math.random() * 10; // it returns a random number that can be anywhere between 0 and 1. The 0 is included and 1 is excluded. | ||
|
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. Comment is clear, well done. |
||
| } | ||
|
|
||
| // Add comments to explain what this function does. You're meant to use Google! | ||
| function combine2Words(word1, word2) { | ||
| return word1.concat(word2); | ||
| // concatenation used inside a function is used to combine words | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,10 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(num){ | ||
| let salesTax = num * 0.2 + num; | ||
| return salesTax; | ||
| } | ||
|
|
||
| /* | ||
| CURRENCY FORMATTING | ||
|
|
@@ -17,7 +20,12 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(num) { | ||
|
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 amazing code. Making use of good naming conventions and ignoring unclear function names. |
||
| let salesTax = num * 0.2 + num; | ||
| return "£" + salesTax.toFixed(2); | ||
| } | ||
| var result2 = addTaxAndFormatCurrency(15); | ||
| console.log(result2); | ||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
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.
Amazing use of the javascript syntax.