-
-
Notifications
You must be signed in to change notification settings - Fork 195
BIRMINGHAM | ITP-MAY-25|Emin Akturk | Sprint 1 #617
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 6 commits
84e3bca
3c9fb3a
c882576
8ccf3b2
d0c0bd7
721fe57
f2f56be
421bdf2
f978685
ed5a1b5
e57d878
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,9 +1,20 @@ | ||
const minimum = 1; | ||
const maximum = 100; | ||
const num = 2; | ||
|
||
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
|
||
// 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 | ||
|
||
|
||
|
||
// SOLUTION: | ||
|
||
// num represents a random number between the minimum and maximum values. | ||
|
||
// program is designed for num to return random numbers between 1-100. | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//expressions of math.floor and math.random are there for //generating a random number between the minimum and maximum values and then rounding it down to the nearest whole number... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
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? | ||
We don't want the computer to run these 2 lines - how can we solve this problem? | ||
|
||
// We can use a comment to prevent the computer from running these lines. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
// trying to create an age variable and then reassign the value by 1 | ||
|
||
const age = 33; | ||
let age = 33; | ||
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}`); | ||
|
||
//Code was correct, I just shifted the const part to the top of the code block. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
const cardNumber = 4533787178994213; | ||
const last4Digits = cardNumber.slice(-4); | ||
const last4Digits = cardNumber.toString().slice(-4); | ||
|
||
|
||
console.log(last4Digits); | ||
|
||
// The last4Digits variable should store the last 4 digits of cardNumber | ||
// However, the code isn't working | ||
// Before running the code, make and explain a prediction about why the code won't work | ||
// Then run the code and see what error it gives. | ||
// Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
// Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
|
||
|
||
// Prediction; code wont work because slice is for strings, not numbers. | ||
|
||
// after running the code, I got an error saying "cardNumber.slice is not a function". | ||
|
||
// It's what I predicted. | ||
|
||
// to fix the code I need to convert number to string first, then slice it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
//const 12HourClockTime = "20:53"; | ||
//const 24hourClockTime = "08:53"; | ||
|
||
|
||
// problem is in javascript we cant start a variable name with a number. | ||
|
||
// correct way is: | ||
|
||
const.twelveHourClockTime = "20:53"; | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const twentyFourHourClockTime = "08:53"; | ||
|
||
console.log(`The time in 12-hour format is ${twelveHourClockTime} and in 24-hour format is ${twentyFourHourClockTime}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,13 @@ console.log(`£${pounds}.${pence}`); | |
|
||
// To begin, we can start with | ||
// 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
|
||
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): This line removes the trailing 'p' from the string. | ||
|
||
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): This line puts the string into a 3 character string padding with zeros. | ||
|
||
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): This line takes out the pounds part of the string. | ||
|
||
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): This line takes out pence part and pads it to 2 characters. | ||
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. Could we expect this program to work as intended for any valid 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. You can also just answer the question here. |
||
|
||
// 6. console.log(`£${pounds}.${pence}`): This line prints the final results. |
Uh oh!
There was an error while loading. Please reload this page.