-
-
Notifications
You must be signed in to change notification settings - Fork 119
ITP JAN 2025 LONDON| ELFREDAH KEVIN-ALERECHI |Structuring-and-Testing-Data| SPRINT 1 #445
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
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,11 +1,11 @@ | ||
let firstName = "Creola"; | ||
let middleName = "Katherine"; | ||
let lastName = "Johnson"; | ||
let firstName = "Elfredah"; | ||
let middleName = "Kevin"; | ||
let lastName = "Alerechi"; | ||
|
||
// Declare a variable called initials that stores the first character of each string. | ||
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. | ||
|
||
let initials = ``; | ||
let initials = "firstName[0] + middleName[0] + lastName[0]"; | ||
|
||
// https://www.google.com/search?q=get+first+character+of+string+mdn | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,9 @@ console.log(`The base part of ${filePath} is ${base}`); | |
// Create a variable to store the dir part of the filePath variable | ||
// Create a variable to store the ext part of the variable | ||
|
||
const dir = ; | ||
const ext = ; | ||
//SOLUTIONS BELOW | ||
|
||
const dir ="filePath.slice(0, lastSlashIndex)"; | ||
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. This statement does not assign the dir part to |
||
const ext = base.split(".").pop(); | ||
|
||
// https://www.google.com/search?q=slice+mdn |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
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,5 +1,9 @@ | ||
// 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"; | ||
//The error occurs because you are trying to use the variable cityOfBirth before it is defined. | ||
// In JavaScript, the line const cityOfBirth = "Bolton"; | ||
// needs to run before you try to use cityOfBirth in the console.log() statement. See the corrected code below: | ||
|
||
const cityOfBirth = "Bolton"; // First, define the variable | ||
console.log(`I was born in ${cityOfBirth}`); // Then, use it |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
const cardNumber = 4533787178994213; | ||
const last4Digits = cardNumber.slice(-4); | ||
const last4Digits = cardNumber.slice(-4); // This will throw an error | ||
|
||
// 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 | ||
|
||
//SOLUTION BELOW | ||
|
||
//The code will not work because cardNumber is a number, and the .slice() method is used for strings, not numbers. | ||
// The .slice() method cannot be used directly on a number, which will lead to an error. | ||
//TypeError: cardNumber.slice is not a function. | ||
//This happens because .slice() is a method that only works on strings and arrays, but cardNumber is a number. | ||
// You can't call .slice() on a number. | ||
//To fix this, we need to convert the number to a string before using .slice() to extract the last 4 digits: | ||
|
||
const cardNumber = 4533787178994213; | ||
const last4Digits = String(cardNumber).slice(-4); // Convert to string first | ||
console.log(last4Digits); // This will output "4213" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
//CORRECTED CODE BLOW | ||
const twelveHourClockTime = "20:53"; // Use letters instead of starting with a number | ||
const twentyFourHourClockTime = "08:53"; // Use letters instead of starting with a number | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,61 @@ console.log(`The percentage change is ${percentageChange}`); | |
// d) Identify all the lines that are variable declarations | ||
|
||
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
|
||
//There are two function calls in the file. They are: | ||
|
||
//a. carPrice.replaceAll(",", "") – This calls the replaceAll() method to remove commas from the carPrice string. | ||
//priceAfterOneYear.replaceAll(",", "") – This also calls the replaceAll() method to remove commas from the priceAfterOneYear string. | ||
|
||
//FULL RESPONSE BELOW: | ||
|
||
// --- CODE STARTS HERE --- | ||
|
||
let carPrice = "10,000"; | ||
let priceAfterOneYear = "8,543"; | ||
|
||
// Removing commas and converting to numbers | ||
carPrice = Number(carPrice.replaceAll(",", "")); | ||
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
||
const priceDifference = carPrice - priceAfterOneYear; | ||
const percentageChange = (priceDifference / carPrice) * 100; | ||
|
||
console.log(`The percentage change is ${percentageChange}`); | ||
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 be added here 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. Thanks. % has been added to console.log( |
||
|
||
// --- QUESTIONS & ANSWERS --- | ||
|
||
// a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
// Answer: | ||
// There are 5 function calls: | ||
// Line 4: carPrice.replaceAll(",", "") | ||
// Line 4: Number(...) | ||
// Line 5: priceAfterOneYear.replaceAll(",", "") | ||
// Line 5: Number(...) | ||
// Line 8: console.log(...) | ||
|
||
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? | ||
// Answer: | ||
// The original error was in line 5 due to a missing comma in replaceAll. | ||
// Incorrect: replaceAll("," "") | ||
// Corrected: replaceAll(",", "") | ||
// The error occurred because the function call had incorrect syntax, missing a second argument. | ||
// Fix: Add the missing comma in replaceAll | ||
|
||
// c) Identify all the lines that are variable reassignment statements | ||
// Answer: | ||
// Line 4: carPrice is reassigned with a numeric version | ||
// Line 5: priceAfterOneYear is reassigned with a numeric version | ||
|
||
// d) Identify all the lines that are variable declarations | ||
// Answer: | ||
// Line 1: let carPrice = "10,000"; | ||
// Line 2: let priceAfterOneYear = "8,543"; | ||
// Line 6: const priceDifference = ... | ||
// Line 7: const percentageChange = ... | ||
|
||
// e) Describe what the expression Number(carPrice.replaceAll(",", "")) is doing - what is the purpose of this expression? | ||
// Answer: | ||
// First, carPrice.replaceAll(",", "") removes commas from the string, turning "10,000" into "10000" | ||
// Then, Number(...) converts the string "10000" into the number 10000 | ||
// The purpose is to convert a formatted price string into a number so that mathematical operations can be performed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,12 @@ In the Chrome console, | |
invoke the function `alert` with an input string of `"Hello world!"`; | ||
|
||
What effect does calling the `alert` function have? | ||
//RESPONSE | ||
It says undefined | ||
Comment on lines
13
to
+15
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. Didn't you see anything happened in the browser when your call |
||
|
||
Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. | ||
|
||
What effect does calling the `prompt` function have? | ||
//It popup a field to add my name | ||
What is the return value of `prompt`? | ||
It says undefined | ||
Comment on lines
21
to
+22
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.
|
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.
With this statement, the value assigned to
initials
is not "EKA" (the first character of each string).