Skip to content

Commit f71288b

Browse files
committed
Mandatory errors were fixed and Explained
1 parent 739e416 commit f71288b

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

Sprint-1/2-mandatory-errors/0.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
12
This is just an instruction for the first activity - but it is just for human consumption
2-
We don't want the computer to run these 2 lines - how can we solve this problem?
3+
We don't want the computer to run these 2 lines - how can we solve this problem?
4+
5+
//solution: Simply comment the lines.
6+
// 1- single line comment like: // example ...
7+
// 2- multiline comment like : /* a, b, c */
8+
// comments are for instruction of guidance of who will read our codes, but the computer wont read them.

Sprint-1/2-mandatory-errors/1.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// trying to create an age variable and then reassign the value by 1
22

33
const age = 33;
4-
age = age + 1;
4+
//age = age + 1;
5+
6+
// we can't do that with const variable, because JS locks the reference.
7+
// the best choice is to use "let" variable.
8+
let age2 = 33;
9+
age2 = age2 + 1; // or age++ if wanna increase by "1";
10+
console.log(age2);

Sprint-1/2-mandatory-errors/2.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
//const cityOfBirth = "Bolton";
7+
8+
// the problem is that our variable is not declared when we print it.
9+
// to make it work, we should declare our "cityOfBirth" variable before we print it.

Sprint-1/2-mandatory-errors/3.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
//const last4Digits = cardNumber.slice(-4);
3+
let str = cardNumber.toString().slice(-4);
4+
const last4Digits = Number(str);
5+
console.log(`${last4Digits} is the last 4 digits of ${cardNumber}`);
6+
7+
//console.log(typeof last4Digits);
8+
9+
// 1- the code is not working because 'slice()' method is not working with numbers.
10+
// 2- it gives "type error" cardNumber.slice is not a function.
11+
// 3- my prediction was correct as I studied the slice method and knew it.
312

413
// The last4Digits variable should store the last 4 digits of cardNumber
514
// However, the code isn't working

Sprint-1/2-mandatory-errors/4.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
/*
12
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
3+
const 24hourClockTime = "08:53";
4+
*/
5+
// As far as I know we can not start a variable name with a number in JS.
6+
// Therefore these variables throw error.
7+
// we can start the name of a variable with letters a-z, A-Z, _ ,and $ .
8+
// This is how we correctly name our variables:
9+
const twelveHourClockTime = "20:53";
10+
const twenty4HourClockTime = "08:53";
11+
console.log(`Twelve-hour clock: ${twelveHourClockTime}`);
12+
console.log(`24-hour clock: ${twenty4HourClockTime}`);

0 commit comments

Comments
 (0)