-
-
Notifications
You must be signed in to change notification settings - Fork 240
London | 25-ITP-Sep | Payman Issa Baiglu | Sprint 2 | Coursework/sprint 2 #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
2c6aae7
876bf7b
058c055
c8cebbb
a5bdca3
7ea670b
f5b79bf
b760859
1f37466
e943a03
5f29b84
8ecd330
0e37a64
cd942b8
906778c
ed909e1
d486397
6eb8b88
62492e1
25347a2
ba8d606
b185d08
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,13 +1,19 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // it gives us an error. | ||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| // function capitalise(str) { | ||
| // let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return str; | ||
| // } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here : | ||
| // as the variable in side the function has the same name as the function variable. | ||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| let str1 = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str1; | ||
|
||
| } | ||
| console.log(capitalise("abcd")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,32 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // error on line 11 | ||
| // error on line 17 | ||
| // Why will an error occur when this program runs? yes | ||
| // =============> write your prediction here | ||
| // decimalNumber is declared before and can not be declared again. | ||
| // console.log(decimalNumber) should be console.log(convertToPercentage) | ||
|
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. This is correct but why is that a case? Why we can't do |
||
| // Try playing computer with the example to work ot what is going on | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
| // function convertToPercentage(decimalNumber) { | ||
| // // const decimalNumber = 0.5; | ||
| // const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
| // return percentage; | ||
| // } | ||
|
|
||
| console.log(decimalNumber); | ||
| //console.log(percentage); | ||
|
|
||
| // =============> write your explanation here | ||
| // decimalNumber is declared before and can not be declared again. | ||
| // console.log(decimalNumber) should be console.log(convertToPercentage) | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function convertToPercentage(decimalNumber) { | ||
| //const decimalNumber = 0.5; | ||
|
||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
|
||
| } | ||
|
|
||
| console.log(convertToPercentage(0.5)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,20 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // it looks fine. | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
| // function multiply(a, b) { | ||
| // console.log(a * b); | ||
| //} | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| // console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // It misses the return value of multiply function. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| return a * b; | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,19 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // there is an error on line 5 and 6 | ||
| //function sum(a, b) { | ||
| // //return; | ||
| // a + b; | ||
| // } | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| //the return statement is not returning any value. a+b declared after return. | ||
PaymanIB marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,23 +2,35 @@ | |
|
|
||
| // Predict the output of the following code: | ||
| // =============> Write your prediction here | ||
| // the result will be 3 times | ||
|
||
| // const num = 103; | ||
|
|
||
| const num = 103; | ||
| // function getLastDigit() { | ||
| // return num.toString().slice(-1); | ||
| // } | ||
|
|
||
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
| // console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| // console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| // console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // =============> write the output here | ||
| //The last digit of 42 is 3 | ||
| // The last digit of 105 is 3 | ||
| // The last digit of 806 is 3 | ||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // because num is defined as 103 and not taking any input from the function parameter. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function getLastDigit(num) { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
| // This program should tell the user the last digit of each number. | ||
| // Explain why getLastDigit is not working properly - correct the problem | ||
| // because num is defined as 103 and not taking any input from the function parameter. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,20 @@ | |
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
|
|
||
|
|
||
| function toPounds(penceString){ | ||
|
|
||
| const penceStringWithoutTrailingP = penceString.substring(0 , penceString.length - 1); | ||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); | ||
| const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); | ||
|
|
||
| return `£${pounds}.${pence}`; | ||
|
||
|
|
||
| } | ||
| console.log(toPounds("399p")); | ||
| console.log(toPounds("50p")); | ||
| console.log(toPounds("5p")); | ||
| console.log(toPounds("0p")); | ||
| console.log(toPounds("12345p")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,31 +4,35 @@ function pad(num) { | |
|
|
||
| function formatTimeDisplay(seconds) { | ||
| const remainingSeconds = seconds % 60; | ||
| const totalMinutes = (seconds - remainingSeconds) / 60; | ||
| const remainingMinutes = totalMinutes % 60; | ||
| const totalMinutes = (seconds - remainingSeconds) / 60; //1 | ||
| const remainingMinutes = totalMinutes % 60; //1 | ||
|
||
| const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
|
|
||
| return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; | ||
| } | ||
|
|
||
|
|
||
| // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit | ||
| // to help you answer these questions | ||
|
|
||
| // Questions | ||
|
|
||
| // a) When formatTimeDisplay is called how many times will pad be called? | ||
| // =============> write your answer here | ||
| // 3 times | ||
|
|
||
| // Call formatTimeDisplay with an input of 61, now answer the following: | ||
| console.log(formatTimeDisplay(61)); | ||
|
|
||
| // b) What is the value assigned to num when pad is called for the first time? | ||
| // =============> write your answer here | ||
|
|
||
| // 0 | ||
| // c) What is the return value of pad is called for the first time? | ||
| // =============> write your answer here | ||
|
|
||
| // "00" | ||
| // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
|
|
||
| // 1, because remainingSeconds is 1 when pad is called for the last time. | ||
| // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
| // "01", because pad adds a leading zero to single digit numbers. | ||
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 try to be more specific, what type of error?