-
-
Notifications
You must be signed in to change notification settings - Fork 475
London 9 - Lovelace - Oleksii Chepurnyi - JavaScript-Core1-Coursework-Week1 #435
base: master
Are you sure you want to change the base?
Changes from all commits
6e80e6e
4bf5b49
2fc87fb
2a4378d
596420b
25b1baa
fad3f7e
7c38916
b9d60af
d9011c4
06113c5
9d801b4
4e0dc67
c743152
2d32725
21df378
683f499
7a31cec
51f831b
d5006a9
1af7570
4e7e47d
897c770
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(78967868678); | ||
|
|
||
| console.log("Hello World.I just started learning JavaScript!"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `greeting` | ||
|
|
||
| var greeting = "Hello world"; | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
| 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"; | ||
| var messageType = typeof message; | ||
| console.log(message); | ||
| console.log(messageType); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `message` | ||
| var greetingStart = "Hello, my name is "; | ||
| var name1 = "Oleks. "; | ||
| var you = "And you ? " | ||
| var greeting = greetingStart + name1 + you; | ||
|
|
||
| console.log(message); | ||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,25 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| var name1 = "Oleks"; | ||
| var nameLength = name1.length; | ||
| var introduce1 = " My name is Oleks and my name is "; | ||
| var introduce2 = "characters long."; | ||
| var message = introduce1 + nameLength + " " + introduce2; | ||
| console.log(message); | ||
| // second way | ||
| var name1 = "Oleks"; | ||
| var nameLength = name1.length; | ||
| var introduce1 = " My name is "; | ||
| var introduce3 = "and my name is "; | ||
| var introduce2 = "characters long."; | ||
| var message = introduce1 + name1 + " "+ introduce3 + | ||
| nameLength + " " + introduce2; | ||
| console.log(message); | ||
| // trim method | ||
| var name1 = "Oleks"; | ||
| var nameLength = name1.length; | ||
| var introduce1 = " My name is "; | ||
| var introduce3 = "and my name is "; | ||
| var introduce2 = "characters long."; | ||
| var message = | ||
| introduce1 + name1 + " " + introduce3 + nameLength + " " + introduce2; | ||
| console.log(message.trim()); | ||
|
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! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,20 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| var name1 = "Oleks"; | ||
| var nameLength = name1.length; | ||
| var introduce1 = " My name is "; | ||
|
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 all the whitespace at the start? |
||
| var introduce3 = "and my name is "; | ||
| var introduce2 = "characters long."; | ||
| var message = | ||
| introduce1 + name1 + " " + introduce3 + nameLength + " " + introduce2; | ||
| console.log(message); | ||
| // trim method | ||
| var name1 = "Oleks"; | ||
| var nameLength = name1.length; | ||
| var introduce1 = " My name is "; | ||
| var introduce3 = "and my name is "; | ||
| var introduce2 = "characters long."; | ||
| var message = | ||
| introduce1 + name1 + " " + introduce3 + nameLength + " " + introduce2; | ||
| console.log(message.trim()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| var numberOfStudents = 50; | ||
| var numberOfMentors = 10; | ||
| var stud = "Number of students: "; | ||
| console.log(stud + numberOfStudents); | ||
| var ment = "Number of mentors: "; | ||
| console.log(ment + numberOfMentors); | ||
| var total = "Total number of students and mentors: "; | ||
| var sum = numberOfMentors + 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. Great 👍 |
||
| console.log(total + sum); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,29 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| var preciseAge = 30.612437; | ||
| varroughAge = Math.round(preciseAge); // 30 | ||
| console.log(varroughAge); | ||
|
|
||
| //from G ex + new solution | ||
|
|
||
| var stud = "Number of students: "; | ||
| console.log(stud + numberOfStudents); | ||
| var ment = "Number of mentors: "; | ||
| console.log(ment + numberOfMentors); | ||
| var total = "Total number of students and mentors: "; | ||
| var sum = numberOfMentors + numberOfStudents; | ||
| console.log(total + sum); | ||
| var percentageStudents = 100*numberOfStudents/sum | ||
|
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' forget the |
||
| var percentageMentors = 100*numberOfMentors/sum | ||
| var roundStudents = Math.round(percentageStudents); | ||
| var roundMentors = Math.round(percentageMentors); | ||
|
|
||
| console.log("Percentage mentors: " + roundMentors + " %."); | ||
| console.log("Percentage students: " + roundStudents + " %."); | ||
| // Result | ||
| // 31 | ||
| // Number of students: 15 | ||
| // Number of mentors: 8 | ||
| // Total number of students and mentors: 23 | ||
| // Percentage mentors: 35 %. | ||
| // Percentage students: 65 %. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,21 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number/2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| console.log("result 12/2=", result); | ||
|
|
||
| console.log(result); | ||
| var result = halve(24); | ||
| console.log("result 24/2=", result); | ||
|
|
||
| var result = halve(100); | ||
| console.log("result 100/2=", result); | ||
|
|
||
| var result = halve(365); | ||
|
|
||
| console.log("result 365/2=", result); | ||
|
|
||
| // result 12/2= 6 | ||
| // result 24/2= 12 | ||
| // result 100/2= 50 | ||
| // result 365/2= 182.5 |
| 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); | ||
| console.log("result 12 x 3 = ", result); | ||
|
|
||
| // result 12 x 3 = 36 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| // Calculate the result of the function and return it | ||
| function multiply(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. Perfect |
||
| return a * b; | ||
| } | ||
|
|
||
| // Assign the result of calling the function the variable `result` | ||
| var result = multiply(3, 4); | ||
|
|
||
| console.log(result); | ||
| console.log("result 3*4 = ", 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; | ||
|
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. The indentation of this line is 4 characters, while you use 1 above in your code. Again, for the sake of consistency and readability, always use the same amount. |
||
| } | ||
| var result = divide(3, 4); | ||
|
|
||
| console.log(result); | ||
| console.log("a / b = ", result); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // Write your function here | ||
|
|
||
| function createGreeting(name) { | ||
| return ("Hello, my name is " + name ); | ||
| } | ||
| var greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); | ||
|
|
||
| // Hello, my name is Daniel |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Declare your function first | ||
|
|
||
| function summ(a, b) { | ||
| return a + b | ||
| } | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); | ||
| var sum = summ(13, 124); | ||
| console.log("13 + 124 = ", 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 am " | ||
| + age + " years old") | ||
| } | ||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); | ||
|
|
||
|
|
||
| // Hello, my name is Daniel and I am 30 years old |
| 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) { | ||
|
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 you meant |
||
| let dol = (price*1.4).toFixed(2); | ||
| return Number(dol); | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| CURRENCY CONVERSION | ||
|
|
@@ -15,7 +19,9 @@ 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 Number((price*0.99*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. | ||
|
|
||
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.
You should avoid
var. As mentioned last week, prefer usingletorconst.varis old, has tricky semantics, and is no longer needed.