-
-
Notifications
You must be signed in to change notification settings - Fork 237
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 15 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 |
---|---|---|
|
@@ -12,14 +12,52 @@ console.log(result); | |
// For the piece of code above, read the code and then answer the following questions | ||
|
||
// a) How many variable declarations are there in this program? | ||
/* There are 6 variable declarations: | ||
1.Line 1 : const movieLength. | ||
2.Line 3 : const remainingSeconds. | ||
3.Line 4 : const totalMinutes. | ||
4.Line 6 : const remainingMinutes. | ||
5.Line 7 : const totalHours. | ||
6.Line 9 : const result. | ||
*/ | ||
|
||
// b) How many function calls are there? | ||
|
||
/* There is one function call: | ||
Line 10 : console.log(). | ||
*/ | ||
|
||
// c) Using documentation, explain what the expression movieLength % 60 represents | ||
|
||
/* The movieLength shows the length of the movie in seconds, the operand % is remaining (Modulo) returns the remaining of the movieLength divided by 60(to convert sec into minutes) but it only gives the remaining of this operation. | ||
*/ | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
||
// d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
||
/* | ||
The expression gives the completed total minutes of the movie, by subtract the movie length in sec from the remaining seconds and divide the result by 60 to convert it to minutes | ||
|
||
*/ | ||
|
||
// e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
||
/* | ||
The variable result shows(display) the total length of the movie in three sections (Hours:Minutes:seconds) in string format. | ||
|
||
I can think of "MovieDuration" as a better name because it gives more description to the output. | ||
|
||
*/ | ||
|
||
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
||
/* | ||
I did experimenting the code by putting different value to the movieLength and it works just fine. | ||
|
||
test numbers and its outcomes: | ||
1. 8689693484 sec >> 2413803:44:44 | ||
2. 12 sec >> 0:0:12 | ||
3. 0 sec >> 0:0:0 | ||
4. -700 sec >> 0:-11:-40 | ||
|
||
As the results show the code is working fine even with unexpected negative numbers or large numbers. | ||
*/ |
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.