Skip to content

Commit e8730e3

Browse files
Removed the double quote on the variable cardNuber value to make the value a number data type
1 parent 9460b09 commit e8730e3

13 files changed

Lines changed: 290 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const cardNumber = "4533787178994213";
1+
const cardNumber = 4533787178994213;
22
//console.log(typeof cardNumber);
33

44
const last4Digits = cardNumber.slice(-4);

Sprint-2-backup/1-key-errors/0.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Predict and explain first... /*There will be a syntax error in the code because the variable `str` is being declared twice within the same scope. The first declaration is in the function parameter, and the second declaration is inside the function body. This will cause a "SyntaxError: Identifier 'str' has already been declared" error.*?
2+
// =============> write your prediction here // there will be an error message as such SyntaxError: Identifier 'str' has already been declared
3+
4+
// call the function capitalise with a string input// capitalise("tobias");
5+
// interpret the error message and figure out why an error is occurring, /*
6+
7+
/*function capitalise(str) {
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return str;
10+
}*/
11+
// =============> write your explanation here
12+
13+
14+
/*/home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/0.js:8
15+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
16+
^
17+
18+
SyntaxError: Identifier 'str' has already been declared
19+
at Object.compileFunction (node:vm:353:18)
20+
at wrapSafe (node:internal/modules/cjs/loader:1039:15)
21+
at Module._compile (node:internal/modules/cjs/loader:1073:27)
22+
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
23+
at Module.load (node:internal/modules/cjs/loader:989:32)
24+
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
25+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
26+
at node:internal/main/run_main_module:17:47*/
27+
// from the error message above the error occurred at line 8 where the variable `str` was declared again using `let` inside the function body, which is not allowed since `str` was already declared as a parameter of the function.
28+
// to fix this error, we can either rename the variable inside the function body or remove the `let` keyword and just assign a new value to `str` without redeclaring it.
29+
30+
// =============> write your new code here
31+
function capitalise(str) {
32+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
33+
return str;
34+
}
35+
capitalise("tobias");
36+
console.log(capitalise("tobias")); // Output: "Tobias"
37+

Sprint-2-backup/1-key-errors/1.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Predict and explain first...
2+
/* There will be a syntax error in the code because the variable `decimalNumber` is being declared twice within the same scope. The first declaration is in the function parameter, and the second declaration is inside the function body. This will cause a "SyntaxError: Identifier 'decimalNumber' has already been declared" error. secondly variable `decimalNumber` is being logged to the console outside of the function, which will also cause a ReferenceError since `decimalNumber` is not defined in that scope.*/
3+
4+
// Why will an error occur when this program runs?/* The variable 'decimalNumber ' is being redeclared inside the function, which is not allowed since it was already declared as a parameter of the function. And the variable `decimalNumber` is being logged to the console outside of the function, which will cause a ReferenceError since `decimalNumber` is not defined in that scope.*/
5+
// =============> write your prediction here. // This will cause a syntax error, additionally also cause a reference error since the variable `decimalNumber` is being logged to the console outside of the function, which will also cause a ReferenceError since `decimalNumber` is not defined in that scope.
6+
7+
8+
// Try playing computer with the example to work out what is going on
9+
10+
function convertToPercentage(decimalNumber) {
11+
const decimalNumber = 0.5;
12+
const percentage = `${decimalNumber * 100}%`;
13+
14+
return percentage;
15+
}
16+
17+
console.log(decimalNumber);
18+
19+
// =============> write your explanation here
20+
21+
// Finally, correct the code to fix the problem
22+
// =============> write your new code here
23+
24+
/*/home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/1.js:11
25+
const decimalNumber = 0.5;
26+
^
27+
28+
SyntaxError: Identifier 'decimalNumber' has already been declared
29+
at Object.compileFunction (node:vm:353:18)
30+
at wrapSafe (node:internal/modules/cjs/loader:1039:15)
31+
at Module._compile (node:internal/modules/cjs/loader:1073:27)
32+
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
33+
at Module.load (node:internal/modules/cjs/loader:989:32)
34+
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
35+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
36+
at node:internal/main/run_main_module:17:47*/

Sprint-2-backup/1-key-errors/2.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
// Predict and explain first BEFORE you run any code...
3+
4+
// this function should square any number but instead we're going to get an error
5+
6+
// =============> write your prediction of the error here
7+
8+
function square(3) {
9+
return num * num;
10+
}
11+
12+
// =============> write the error message here
13+
14+
// =============> explain this error message here
15+
16+
// Finally, correct the code to fix the problem
17+
18+
// =============> write your new code here
19+
20+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Predict and explain first...
2+
3+
// =============> write your prediction here
4+
5+
function multiply(a, b) {
6+
console.log(a * b);
7+
}
8+
9+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10+
11+
// =============> write your explanation here
12+
13+
// Finally, correct the code to fix the problem
14+
// =============> write your new code here
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Predict and explain first...
2+
// =============> write your prediction here
3+
4+
function sum(a, b) {
5+
return;
6+
a + b;
7+
}
8+
9+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10+
11+
// =============> write your explanation here
12+
// Finally, correct the code to fix the problem
13+
// =============> write your new code here
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Predict and explain first...
2+
3+
// Predict the output of the following code:
4+
// =============> Write your prediction here
5+
6+
const num = 103;
7+
8+
function getLastDigit() {
9+
return num.toString().slice(-1);
10+
}
11+
12+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15+
16+
// Now run the code and compare the output to your prediction
17+
// =============> write the output here
18+
// Explain why the output is the way it is
19+
// =============> write your explanation here
20+
// Finally, correct the code to fix the problem
21+
// =============> write your new code here
22+
23+
// This program should tell the user the last digit of each number.
24+
// Explain why getLastDigit is not working properly - correct the problem
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Below are the steps for how BMI is calculated
2+
3+
// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.
4+
5+
// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by:
6+
7+
// squaring your height: 1.73 x 1.73 = 2.99
8+
// dividing 70 by 2.99 = 23.41
9+
// Your result will be displayed to 1 decimal place, for example 23.4.
10+
11+
// You will need to implement a function that calculates the BMI of someone based off their weight and height
12+
13+
// Given someone's weight in kg and height in metres
14+
// Then when we call this function with the weight and height
15+
// It should return their Body Mass Index to 1 decimal place
16+
17+
function calculateBMI(weight, height) {
18+
// return the BMI of someone based off their weight and height
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// A set of words can be grouped together in different cases.
2+
3+
// For example, "hello there" in snake case would be written "hello_there"
4+
// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces.
5+
6+
// Implement a function that:
7+
8+
// Given a string input like "hello there"
9+
// When we call this function with the input string
10+
// it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE"
11+
12+
// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS"
13+
14+
// You will need to come up with an appropriate name for the function
15+
// Use the MDN string documentation to help you find a solution
16+
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// In Sprint-1, there is a program written in interpret/to-pounds.js
2+
3+
// You will need to take this code and turn it into a reusable block of code.
4+
// You will need to declare a function called toPounds with an appropriately named parameter.
5+
6+
// You should call this function a number of times to check it works for different inputs

0 commit comments

Comments
 (0)