-
-
Notifications
You must be signed in to change notification settings - Fork 238
Glasgow | 25-ITP-SEP | Fares Bakhet | Sprint 1 | coursework/sprint-1 #724
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 all commits
76d363e
6164830
8c6bab4
c8bf5bd
8e7295c
636a0d3
1e77924
b757594
6304885
dd1938f
4d88daa
69b5489
7fdaec0
6673a2a
21a7389
8760633
c67261d
b763d76
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,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,5 @@ | ||
// trying to create an age variable and then reassign the value by 1 | ||
|
||
const age = 33; | ||
age = age + 1; | ||
let age = 30; // Change const to let to allow reassignment | ||
age += 1; // Increment age by 1 | ||
console.log(age); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
/* The old code: | ||
const cardNumber = 4533787178994213; | ||
const last4Digits = cardNumber.slice(-4); | ||
*/ | ||
|
||
// 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 | ||
|
||
/* My prediction: The code will give an error because the minus sign(-4) and slice works only with strings, not numbers. | ||
|
||
Consideration: The error is a TypeError: cardNumber.slice is not a function. mostly it was because I predicted that numbers do not have a slice method. About the minus sign, I have learned about positive and negative indexing in strings, now I can see the difference. | ||
|
||
|
||
To fix this, we need to convert cardNumber to a string before calling the slice method. | ||
*/ | ||
|
||
// Updated code: | ||
const cardNumber = 4533787178994213; | ||
const last4DigitsCorrected = cardNumber.toString().slice(-4); | ||
console.log(last4DigitsCorrected); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
/* | ||
The old code: | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
const 24hourClockTime = "08:53"; | ||
console.log(24hourClockTime);*/ | ||
|
||
// It is giving a syntax error | ||
// The reason is that variable names cannot start with a number | ||
|
||
// Updated code: | ||
const hourClockTime12 = "20:53"; | ||
const hourClockTime24 = "08:53"; | ||
console.log(hourClockTime24, hourClockTime12); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,28 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter | |
|
||
What output do you get? | ||
|
||
-The output : ƒ log() { [native code] } | ||
|
||
Now enter just `console` in the Console, what output do you get back? | ||
|
||
-The output : console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} + a lot of functions under it. | ||
|
||
Try also entering `typeof console` | ||
|
||
Answer the following questions: | ||
-The output : object | ||
|
||
-Answer the following questions: | ||
|
||
What does `console` store? | ||
|
||
-Answer : console is an object with debugging methods. | ||
It does not store variables or result. It provide methods for outputting , data , object and more. | ||
|
||
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? | ||
|
||
Answer: | ||
-console is a built-in object. | ||
-log and assert are properties of that object, specifically functions (methods). | ||
-The console.assert() static method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens. | ||
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. for console.assert(condition, message); you provide a boolean expression as the 1st argument and message string if false. 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. @tenzyns , 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. @Fares-Bakhet, Apologies, didn't get notified of this. No you don't need to rephrase. Just to be aware of the what arguments it accepts. |
||
-The console.log() static method outputs a message to the console. | ||
-'.' means use this method from this object. |
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.
priceDifference and percentageChange are also variables. Although their values are fixed after assignment due to the use of the const keyword, they are still considered variables in JavaScript.
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.
@tenzyns, I missed these two🤔😥 I will add them now.
Thanks a lot.