Repository navigation
London | 26-ITP | Mars Adesina | Sprint 2 | Javascript Fundamentals #1559
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 37 commits
269946f
b2c7381
e289781
74a67c9
e25b334
ec30f47
8f87ed4
297191f
8497414
85aded1
c8979e7
71e889b
f0c63cb
a08fe81
014e42a
4d81b9f
95adf58
f920359
7ec6995
ed25b1d
ee9f94c
a16ba75
e3fabaf
34357e2
336102c
6d81f32
baf6433
efa997d
eca4da2
7cf3da9
92b9bcc
d87544b
fc5d38c
91b6ea9
ab155d9
cae3793
157f416
2886191
2de6944
9a8d497
7c792ee
ae092fd
538ff7d
d84d88b
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 |
|---|---|---|
|
|
@@ -2,8 +2,18 @@ const minimum = 1; | |
| const maximum = 100; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
| num = Math.floor(Math.random(0.9) * (100 - 1 + 1)) + 1; | ||
|
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. Run
|
||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // Try breaking down the expression and using documentation to explain what it means | ||
| // It will help to think about the order in which expressions are evaluated | ||
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
| //console.log(num) | ||
| //output: random whole number | ||
|
|
||
| // So num is storing the value of a random number generated by the method Math.random this will be a number between zero and one that is then multiplied by 100 (100(maximum) -1(minimum) +1) and then whatever this number is, one is added on to that number and then finally the Math.floor method will round that number down to the nearest whole number add one and this final number is what is stored in the variable num. | ||
|
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. Two things in this answer. First, you say one is added before Second, finish with what |
||
|
|
||
| //example Math.random () = 0.97 | ||
| //0.97 * 100 = 97 | ||
| //Math.floor = 97 | ||
| //97+1 = 98 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| This is just an instruction for the first activity - but it is just for human consumption | ||
| We don't want the computer to run these 2 lines - how can we solve this problem? | ||
| // This is just an instruction for the first activity - but it is just for human consumption | ||
| // We don't want the computer to run these 2 lines - how can we solve this problem? | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
|
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. The fix is right. The exercise also asks for the error and the reason. The starter had Tip: the error in |
||
| age = age + 1; | ||
|
|
||
| console.log(age); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
| // the variable was initially declared after console.log so it threw an error message. The error message "cannot access 'cityOfBirth' before initialization at Object" is saying that javascript cannot access the variable before it has been initialised. I have initialised the variable on line 3 now so the message prints in the console now. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const TwelveHourClockTime = "8:53pm"; | ||
| const TwentyFourHourClockTime = "20:53"; | ||
| console.log(TwelveHourClockTime); | ||
| console.log(TwentyFourHourClockTime); | ||
|
|
||
| //output: SyntaxError: Invalid or unexpected token | ||
| // Javascript variables cannot start with a number | ||
| // Updated numbers in each variable from 12HourClockTime to TwelveHourClockTime | ||
| //and 24HourClockTime to TwentyFourHourClockTime and both times now print in | ||
| //the console. |
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.
This gives
.txtforfile.txt. What does it give ifbaseisphoto.jpeg?The number 4 only fits a name with four letters. How can you find where the
.is, like you found the last/on line 13?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.
slice(-4)still counts four characters from the end. What does it give forphoto.jpeg?The
.is not always four characters from the end. On line 13 you usedlastIndexOfto find the last/. Can you do the same for the.?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 have made the changes and pushed it now. I didn't think about the slice method not working for every extension type because they differ in length but after reviewing my code on line 13, I understand now why using the lastindex of method for the ext variable is correct here! Thanks so much Abdi!
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.
That's the one. Your comment on line 19 explains it well.