File tree Expand file tree Collapse file tree 11 files changed +29
-90
lines changed
Expand file tree Collapse file tree 11 files changed +29
-90
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> Capitalises the first letter of the str
2+ // =============> write your prediction here
33
44// call the function capitalise with a string input
55// interpret the error message and figure out why an error is occurring
@@ -9,7 +9,5 @@ function capitalise(str) {
99 return str ;
1010}
1111
12- capitalise ( "mohsen" ) ;
13-
14- // =============> variable str is declared again inside function
15- // =============> str = `${str[0].toUpperCase()}${str.slice(1)}`;
12+ // =============> write your explanation here
13+ // =============> write your new code here
Original file line number Diff line number Diff line change 11// Predict and explain first...
22
33// Why will an error occur when this program runs?
4- // =============> Instead of calling the function, a variable is called
4+ // =============> write your prediction here
55
66// Try playing computer with the example to work out what is going on
77
@@ -14,7 +14,7 @@ function convertToPercentage(decimalNumber) {
1414
1515console . log ( decimalNumber ) ;
1616
17- // =============> Also inside the function, decimalNumber is called again
17+ // =============> write your explanation here
1818
1919// Finally, correct the code to fix the problem
20- // =============> decimalNumber = 0.5;
20+ // =============> write your new code here
Original file line number Diff line number Diff line change 33
44// this function should square any number but instead we're going to get an error
55
6- // =============> The variable num is not declared
6+ // =============> write your prediction of the error here
77
88function square ( 3 ) {
99 return num * num ;
1010}
1111
12- // =============>SyntaxError: Unexpected number
12+ // =============> write the error message here
1313
14- // =============> There must a variable declared, not just simply passing a number as an argument
14+ // =============> explain this error message here
1515
1616// Finally, correct the code to fix the problem
1717
18- // =============> function square(num) {
18+ // =============> write your new code here
1919
2020
Original file line number Diff line number Diff line change 11// Predict and explain first...
22
3- // =============> the result of the multiply is printed inside function, and at the function call is will be undefined
3+ // =============> write your prediction here
44
55function multiply ( a , b ) {
66 console . log ( a * b ) ;
77}
88
99console . log ( `The result of multiplying 10 and 32 is ${ multiply ( 10 , 32 ) } ` ) ;
1010
11- // =============> because function is not returning any value
11+ // =============> write your explanation here
1212
1313// Finally, correct the code to fix the problem
14- // =============> return a * b;
14+ // =============> write your new code here
Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> undefined will be printed
2+ // =============> write your prediction here
33
44function sum ( a , b ) {
55 return ;
@@ -8,6 +8,6 @@ function sum(a, b) {
88
99console . log ( `The sum of 10 and 32 is ${ sum ( 10 , 32 ) } ` ) ;
1010
11- // =============> because the function returns nothing
11+ // =============> write your explanation here
1212// Finally, correct the code to fix the problem
13- // =============> return a + b;
13+ // =============> write your new code here
Original file line number Diff line number Diff line change 11// Predict and explain first...
22
33// Predict the output of the following code:
4- // =============> the last digit of every function call will be 3
4+ // =============> Write your prediction here
55
66const num = 103 ;
77
8- function getLastDigit ( num ) {
8+ function getLastDigit ( ) {
99 return num . toString ( ) . slice ( - 1 ) ;
1010}
1111
@@ -16,10 +16,9 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1616// Now run the code and compare the output to your prediction
1717// =============> write the output here
1818// Explain why the output is the way it is
19- // =============> function is using the num declared before it , not the number passed to it
19+ // =============> write your explanation here
2020// Finally, correct the code to fix the problem
21- // =============> function getLastDigit(num) {
21+ // =============> write your new code here
2222
2323// This program should tell the user the last digit of each number.
2424// Explain why getLastDigit is not working properly - correct the problem
25- // Variable num used inside the function, should be passed as an argument
Original file line number Diff line number Diff line change 1515// It should return their Body Mass Index to 1 decimal place
1616
1717function calculateBMI ( weight , height ) {
18- // return the BMI of someone based off their weight and height
19- const bmi = weight / height ** 2 ;
20- return bmi . toFixed ( 1 ) ;
21- }
22- console . log ( calculateBMI ( 70 , 1.73 ) ) ;
18+ // return the BMI of someone based off their weight and height
19+ }
Original file line number Diff line number Diff line change 1414// You will need to come up with an appropriate name for the function
1515// Use the MDN string documentation to help you find a solution
1616// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17- function makeUpperSnakeCase ( str ) {
18- return str . toUpperCase ( ) . split ( " " ) . join ( "_" ) ;
19- }
Original file line number Diff line number Diff line change 44// You will need to declare a function called toPounds with an appropriately named parameter.
55
66// You should call this function a number of times to check it works for different inputs
7-
8- function toPounds ( penceString ) {
9- const penceStringWithoutTrailingP = penceString . substring (
10- 0 ,
11- penceString . length - 1
12- ) ;
13-
14- const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
15- const pounds = paddedPenceNumberString . substring (
16- 0 ,
17- paddedPenceNumberString . length - 2
18- ) ;
19-
20- const pence = paddedPenceNumberString
21- . substring ( paddedPenceNumberString . length - 2 )
22- . padEnd ( 2 , "0" ) ;
23-
24- return `£${ pounds } .${ pence } ` ;
25- }
Original file line number Diff line number Diff line change @@ -17,20 +17,18 @@ function formatTimeDisplay(seconds) {
1717// Questions
1818
1919// a) When formatTimeDisplay is called how many times will pad be called?
20- // =============> 3
21- formatTimeDisplay ( 61 ) ;
20+ // =============> write your answer here
2221
2322// Call formatTimeDisplay with an input of 61, now answer the following:
2423
2524// b) What is the value assigned to num when pad is called for the first time?
26- // =============> 0
25+ // =============> write your answer here
2726
2827// c) What is the return value of pad is called for the first time?
29- // =============> It is called return value and will be '00'
28+ // =============> write your answer here
3029
3130// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
32- // =============> The function is passed 61 which means 1 minute and 1 second so the value passed to pad for the last call is 1
31+ // =============> write your answer here
3332
3433// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
35- // =============> 1 is passed to function as a number and stored in num then num is turned into a string and one '0' will be added
36- // to the beginning of num so the returned value will be '01'
34+ // =============> write your answer here
You can’t perform that action at this time.
0 commit comments