File tree Expand file tree Collapse file tree 4 files changed +10
-13
lines changed
Expand file tree Collapse file tree 4 files changed +10
-13
lines changed Original file line number Diff line number Diff line change 1- const minimum = 1 ;
2- const maximum = 100 ;
3-
1+ const [ min , max ] = [ 1 , 100 ] ;
42const num = Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) + minimum ;
53
64// In this exercise, you will need to work out what num represents?
75// Try breaking down the expression and using documentation to explain what it means
86// It will help to think about the order in which expressions are evaluated
97// Try logging the value of num and running the program several times to build an idea of what the program is doing
108
11- /*num represent any value between 1 to 100.
9+ /*num represents a number in [1, 100] and Math.random() returns a number in [0, 1) .
1210Math.floor is a method that rounds a number down to the nearest whole number.
13- Math.random is a method returning any number that is greater than or equal to 0 and less than 1.
14- first of all i will try to get a value from 0 to less than 1 from Math.random and multiple it by 100
11+ first of all i will try to get a value [0, 1) from Math.random and multiple it by 100
1512and apply Math.floor to the result which will give me the integer number and then add the minimum value i.e. 1 */
Original file line number Diff line number Diff line change 1- const cardNumber = " 4533787178994213" ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
1+ const cardNumber = 4533787178994213 ;
2+ const last4Digits = cardNumber . toString ( ) . slice ( - 4 ) ;
33
44// The last4Digits variable should store the last 4 digits of cardNumber
55// However, the code isn't working
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ console.log(result);
2626//This expression calculates the total full minutes in the movie by removing leftover seconds and converting seconds to minutes.
2727
2828// e) What do you think the variable result represents? Can you think of a better name for this variable?
29- //result represent the total movie length using hours,minutes and seconds,the better name can be totalMovieDuration .
29+ //result represent the total movie length using hours,minutes and seconds,the better name can be movieRunTime .
3030
3131// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
3232/*the code works for different values of movieLength it present the input movieLength by calculating the remainder and subtracting
Original file line number Diff line number Diff line change 1- const penceString = "0p " ;
1+ const penceString = "340210p " ;
22
33const penceStringWithoutTrailingP = penceString . substring (
44 0 ,
@@ -11,9 +11,9 @@ const pounds = paddedPenceNumberString.substring(
1111 paddedPenceNumberString . length - 2
1212) ;
1313
14- const pence = paddedPenceNumberString . substring (
15- paddedPenceNumberString . length - 2
16- ) ;
14+ const pence = paddedPenceNumberString
15+ . substring ( paddedPenceNumberString . length - 2 )
16+ . padEnd ( 2 , "0" ) ;
1717console . log ( `£${ pounds } .${ pence } ` ) ;
1818
1919// This program takes a string representing a price in pence
You can’t perform that action at this time.
0 commit comments