-
-
Notifications
You must be signed in to change notification settings - Fork 475
London 9 - Tony Arora - JavaScript-Core-1-Coursework-Week1 #439
base: master
Are you sure you want to change the base?
Changes from all commits
a58ecdc
8f5ddb1
093f6af
a7fa40b
f30028a
ece1901
5f6040a
6747c60
2eafb34
5f8ab4f
e03156b
1a0fc74
e42c3e6
7a462a4
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,5 @@ | ||
| console.log("Hello world"); | ||
| console.log("finally understood how to use terminal"); | ||
| console.log("gives error without quotes"); | ||
| console.log(100); | ||
| console.log("it gets the number") |
| 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 = "Tony was here"; | ||
| let type= typeof message; | ||
| console.log(message); | ||
| console.log(type); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let first = "My name is"; | ||
| let second = " King Tony"; | ||
| let message = first + second; | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| var name = "tony"; | ||
| var message = name.length; | ||
| console.log(message); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| let message=name.toLowerCase(); | ||
| console.log(message); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1 +1,5 @@ | ||||||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||||||
| let numOfStudents=15; | ||||||
| let numOfMentors=8; | ||||||
|
Contributor
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. Same issue again with spaces. Make sure you come back and tweak these lines 😃
Suggested change
|
||||||
| let abs=numOfMentors+numOfStudents; | ||||||
|
Contributor
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. How can you improve the readability of your code here ? |
||||||
| console.log("the total number of sty and men are:" + abs) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,9 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| var sum=numberOfMentors+numberOfStudents; | ||
| var men=Math.round((numberOfMentors/sum)*100); | ||
| var stu=Math.round((numberOfStudents/sum)*100); | ||
| console.log(men); | ||
| console.log(stu); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number/2 | ||
|
Contributor
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. Same issue with spacing applies here too - you can leave a space between |
||
| } | ||
|
|
||
| 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*number*number | ||
|
Contributor
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. Spacing here 👓
Contributor
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. And semi-colon 😄 |
||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| // Complete the function so that it takes input parameters | ||||||
| function multiply() { | ||||||
| function multiply(a,b) { | ||||||
|
Contributor
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. As with the other statements, in a function declaration here it is also convention to place spaces between parameters:
Suggested change
|
||||||
| // Calculate the result of the function and return it | ||||||
| return a*b | ||||||
| } | ||||||
|
|
||||||
| // Assign the result of calling the function the variable `result` | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Declare your function first | ||
|
|
||
| function divide(a,b){ | ||
| return a/b | ||
| }; | ||
| 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 createGreeting(name){ | ||
| return ("Nice to meet you " + name) | ||
|
Contributor
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. Here you've wrapped the return value in parentheses. |
||
| } | ||
| 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 | ||
|
|
||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| function summed(a,b){ | ||
| return a+b | ||
| }; | ||
| let sum =summed(13,24) | ||
|
Contributor
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(sum); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ | |
| Write a function that converts a price to USD (exchange rate is 1.4 $ to £) | ||
| */ | ||
|
|
||
| function convertToUSD() {} | ||
| function convertToUSD(gbp) { | ||
| return Number((gbp*1.4).toFixed(2)); | ||
| } | ||
|
|
||
| /* | ||
| CURRENCY CONVERSION | ||
|
|
@@ -15,7 +17,10 @@ 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(brazil) { | ||
| let ninetyNine=(brazil*99)/100; | ||
|
Contributor
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. Let's think about how we can make this code even clearer. |
||
| return Number((ninetyNine*5.7).toFixed(2)); | ||
| } | ||
|
|
||
| /* ======= 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 |
|---|---|---|
|
|
@@ -42,13 +42,65 @@ | |
| Outlook not so good. | ||
| Very doubtful. | ||
| */ | ||
| const { toBeOneOf } = require("jest-extended"); | ||
|
|
||
| const veryPositiveAnswers = [ | ||
| "It is certain.", | ||
| "It is decidedly so.", | ||
| "Without a doubt.", | ||
| "Yes - definitely.", | ||
| "You may rely on it.", | ||
| ]; | ||
|
|
||
| const positiveAnswers = [ | ||
| " As I see it, yes.", | ||
| "Most likely.", | ||
| " Outlook good.", | ||
| "Yes.", | ||
| " Signs point to yes.", | ||
| ]; | ||
|
|
||
| const negativeAnswers = [ | ||
| "Reply hazy, try again.", | ||
| "Ask again later.", | ||
| "Better not tell you now.", | ||
| "Cannot predict now.", | ||
| "Concentrate and ask again.", | ||
| ]; | ||
| const veryNegativeAnswers = [ | ||
| "Don't count on it.", | ||
| "My reply is no.", | ||
| "My sources say no.", | ||
| "Outlook not so good.", | ||
| "Very doubtful.", | ||
| ]; | ||
|
|
||
| const listsOfAnswers = [ | ||
| veryPositiveAnswers, | ||
| positiveAnswers, | ||
| negativeAnswers, | ||
| veryNegativeAnswers, | ||
| ]; | ||
|
|
||
| let answer; | ||
|
|
||
| // This should log "The ball has shaken!" | ||
| // and return the answer. | ||
| function shakeBall() { | ||
| //Write your code in here | ||
| console.log("The ball has shaken!") | ||
| answer= randomAnswer(); | ||
| return answer; | ||
| } | ||
| function randomAnswer(){ | ||
| let list=listsOfAnswers[getRandom(4)]; | ||
| let answer=list[getRandom(5)]; | ||
| return answer; | ||
| } | ||
|
|
||
| function getRandom(max){ | ||
| return Math.floor(Math.random()*max); | ||
| } | ||
| /* | ||
| This function should say whether the answer it is given is | ||
| - very positive | ||
|
|
@@ -58,10 +110,28 @@ function shakeBall() { | |
|
|
||
| This function should expect to be called with any value which was returned by the shakeBall function. | ||
| */ | ||
| function checkAnswer(answer) { | ||
| function checkAnswer(string) { | ||
|
Contributor
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 did you change the name of this parameter from |
||
| //Write your code in here | ||
| for (let i=0; i<4;i++){ | ||
| let list=listsOfAnswers[i]; | ||
| for (let j = 0; j < 5; j++) { | ||
|
Contributor
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 attempt at variable naming here! A little wordy perhaps, but easier for me to work out what's going on in your code very quickly. |
||
| let answerFromList = list[j]; | ||
| if (answerFromList === string) { | ||
| if (i === 0) { | ||
| return "very positive"; | ||
| } else if (i === 1) { | ||
| return "positive"; | ||
| } else if (i === 2) { | ||
| return "negative"; | ||
| } else { | ||
| return "very negative"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| ================================== | ||
| ======= TESTS - DO NOT MODIFY ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,11 @@ | |
| Sales tax is 20% of the price of the product. | ||
| */ | ||
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(product) { | ||
| let incTax=product*1.2; | ||
| return incTax; | ||
|
|
||
| } | ||
|
|
||
| /* | ||
| CURRENCY FORMATTING | ||
|
|
@@ -17,7 +21,11 @@ function calculateSalesTax() {} | |
| Remember that the prices must include the sales tax (hint: you already wrote a function for this!) | ||
| */ | ||
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(currency) { | ||
| let first=calculateSalesTax(currency); | ||
|
Contributor
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. Think about your indenting here - how can you update these variable declarations to make your code more readable. Also think about the naming of your variables here again. For example, what does the variable |
||
| let second=first.toFixed(2); | ||
| return `£${second}`; | ||
| } | ||
|
|
||
| /* | ||
| =================================================== | ||
|
|
||
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.
At the moment, you're using
varto declare a varibable. We probably need to update our exercises: however, whenever you're declaring a variable be sure to use theletorconstkeyword. You'll learn more about why this is the case later on in the course.