-
-
Notifications
You must be signed in to change notification settings - Fork 475
London- 9- Lovelace - Howard Sun - JS1-coursework-Week1 #428
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,9 @@ | ||
| console.log("Hello world"); | ||
|
|
||
| let greeting = '1'; | ||
|
|
||
| //console.log(22); | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); | ||
| //console.log("Hi World!"); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // 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,7 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let message = [] ; | ||
| //let messageType = typeof message; | ||
|
|
||
| console.log(message); | ||
| console.log(typeof message); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
| //let messageStart = "Hello, my name is "; | ||
| let messageName = "Daniel"; | ||
| let message = "Hello, my name is " + messageName | ||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| const name = "Daniel"; | ||
| //let messageLength = messageName.length | ||
|
|
||
| //let message = "My name is Daniel and my name is " + messageLength + " characters long"; | ||
| let message = `My name is ${name} and my name is ${name.length} 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. Nice use of string interpolation! |
||
|
|
||
| console.log(message); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| const name = " Johnson "; | ||
| //const trimName = Name.trim(); | ||
| //let nameLength = trimName.length; | ||
|
|
||
| //let message = "My name is " + trimName + " and my name is "+ nameLength + " characters long" | ||
|
|
||
| let message = `My name is ${name.trim()} and my name is ${(name.trim().length)} characters long`; | ||
|
|
||
| console.log(message); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,13 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| let numberOfStudents = 15; | ||
| let numberOfMentors = 10; | ||
|
|
||
| let totalNum = numberOfStudents + numberOfMentors; | ||
|
|
||
| //console.log("Number of students: "+ numberOfStudents); | ||
| //console.log("Number of mentors: " + numberOfMentors); | ||
| //console.log("Total number of students and mentors: "+ totalNum); | ||
|
|
||
| console.log(`Number of students: ${numberOfStudents}`); | ||
| console.log(`Number of mentors: ${numberOfMentors}`); | ||
| console.log(`Total number of students and mentors: ${totalNum}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,13 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| let totalNum = numberOfStudents + numberOfMentors; | ||
|
|
||
| let studentPercentage = (numberOfStudents / totalNum) * 100; | ||
| let mentorPercentage = (numberOfMentors / totalNum) * 100; | ||
|
|
||
| console.log(`Percentage students: ${Math.round(studentPercentage)}%`); | ||
| console.log(`Percentage mentors: ${Math.round(mentorPercentage)}%`); | ||
|
|
||
| //console.log("Percentage students: "+Math.round(studentPercentage)+"%"); | ||
| //console.log("Percentage mentors: " +Math.round(mentorPercentage)+"%"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number / 2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| let result = halve(12); | ||
| // let res2 = halve (88); | ||
| // let res3 = halve (100); | ||
|
|
||
| console.log(result); | ||
|
|
||
| console.log(halve(88)); | ||
| console.log(halve(122)); | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| return number * 3 | ||
| } | ||
|
|
||
| var result = triple(12); | ||
| let result = triple(12); | ||
|
|
||
| console.log(result); | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| function multiply(a,b) { | ||
| // Calculate the result of the function and return it | ||
| } | ||
|
|
||
| return a * b ; | ||
| } | ||
| // Assign the result of calling the function the variable `result` | ||
| var result = multiply(3, 4); | ||
| let result = multiply(3, 4); | ||
|
|
||
| console.log(result); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Declare your function first | ||
|
|
||
| var result = divide(3, 4); | ||
| function divide(a,b) { | ||
| return a / b; | ||
| } | ||
| let result = divide(3, 4); | ||
|
|
||
| console.log(result); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| // Write your function here | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
| function createGreeting(name){ | ||
| // return "Hello, my name is " + name; | ||
| return `Hello, my name is ${name}`; | ||
| } | ||
| let greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Declare your function first | ||
|
|
||
| function add(a,b) { | ||
| return a + b; | ||
| } | ||
| // Call the function and assign to a variable `sum` | ||
| let sum = add(13,124); | ||
|
|
||
| console.log(sum); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Declare your function here | ||
|
|
||
| function createLongGreeting(str,age) { | ||
| //return "Hello, my name is " + str + " and I'm " + age + " years old"; | ||
| return `Hello, my name is ${str} and I'm ${age} years old`; | ||
| } | ||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,38 +4,41 @@ | |
| 1. Write 3 functions: | ||
| - one that adds 2 numbers together | ||
| - one that multiplies 2 numbers together | ||
| - one that formats a number so it's returned as a string with a £ sign before it (e.g. 20 -> £20) | ||
| - one that formats a number so it's returned as a string with a £ sign before | ||
| it (e.g. 20 -> £20) | ||
|
|
||
| 2. Using the variable startingValue as input, perform the following operations using your functions all | ||
| on one line (assign the result to the variable badCode): | ||
| 2. Using the variable startingValue as input, perform the following operations | ||
| using your functions all on one line (assign the result to the variable badCode): | ||
| - add 10 to startingValue | ||
| - multiply the result by 2 | ||
| - format it | ||
|
|
||
| 3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign | ||
| the final result to the variable goodCode | ||
| 3. Write a more readable version of what you wrote in step 2 under the BETTER | ||
| PRACTICE comment. Assign the final result to the variable goodCode | ||
| */ | ||
|
|
||
| function add() { | ||
|
|
||
| function add(a,b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| function multiply() { | ||
|
|
||
| function multiply(a,b) { | ||
| return a * b; | ||
| } | ||
|
|
||
| function format() { | ||
|
|
||
| function format(a) { | ||
| return "£"+a; | ||
| } | ||
|
|
||
| const startingValue = 2; | ||
|
|
||
| // Why can this code be seen as bad practice? Comment your answer. | ||
| let badCode = | ||
| let badCode = format( multiply(2, add(startingValue,10))); | ||
|
|
||
| /* BETTER PRACTICE */ | ||
| let goodadd = add(startingValue,10); | ||
| let goodmultiply = multiply(2,goodadd); | ||
|
|
||
| let goodCode = | ||
| let goodCode = format(goodmultiply); | ||
|
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! |
||
|
|
||
| /* ======= 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 |
|---|---|---|
|
|
@@ -45,8 +45,12 @@ | |
|
|
||
| // This should log "The ball has shaken!" | ||
| // and return the answer. | ||
| function shakeBall() { | ||
| function shakeBall(answer) { | ||
| //Write your code in here | ||
| if ( answer === positive ) { | ||
|
|
||
| console.log("The ball has shaken " + answer ); | ||
|
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, only "The ball has shaken!" should be in the console log. The answer should be picked at random from the possible answers. |
||
| } | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -56,7 +60,8 @@ function shakeBall() { | |
| - negative | ||
| - very negative | ||
|
|
||
| This function should expect to be called with any value which was returned by the shakeBall function. | ||
| This function should expect to be called with any value which was returned | ||
| by the shakeBall function. | ||
| */ | ||
| function checkAnswer(answer) { | ||
| //Write your code in here | ||
|
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 function should take any of the possible random answers and then return if the answer is very positive, positive, negative or very negative. |
||
|
|
||
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.
I know this test passed, but I would normally expect message to be a string and not an array.