-
-
Notifications
You must be signed in to change notification settings - Fork 195
London | ITP-May-2025 | Surafel Workneh | Structuring and testing data | Coursework/sprint 1 #646
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
12eb682
b57e0f3
a7ffaa8
de6389d
3425e3b
fa0ebc7
6697426
61fd838
4a786db
7a0b1f7
6992670
ed5a315
7b076d8
2f5a89b
2fc4c90
e6ec04b
79cc401
61bac86
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,17 @@ | ||
let firstName = "Creola"; | ||
let middleName = "Katherine"; | ||
let lastName = "Johnson"; | ||
// The code above declares these three variables: firstName, middleName, and lastName. | ||
// Each variable is assigned a string value representing each element in the name. | ||
// The task is to create a new variable take initials that combines the first character from each of these strings. | ||
// The initials variable should contain the first letter of each name, resulting in the string "CKJ". | ||
|
||
// 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 = ``; | ||
|
||
initials = firstName[0] + middleName[0] + lastName[0]; | ||
console.log(initials); // Output: CKJ | ||
// The code above uses the bracket notation to access the first character of each string [0]. | ||
// This is a common way to get the first character of a string in JavaScript. | ||
// https://www.google.com/search?q=get+first+character+of+string+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,7 @@ | ||
// 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"; | ||
console.log(`I was born in ${cityOfBirth}`); | ||
|
||
//The error is that the variable cityOfBirth is being used before it has been declared.JavaScript executes code line by line from top to bottom, so you must declare and assign a value to the variable before using it. | ||
// In JavaScript, variables declared with let or const are not hoisted, meaning they cannot be accessed before their declaration. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
// const 12HourClockTime = "20:53"; it is in 24 hour format | ||
// const 24hourClockTime = "08:53"; it is in 12 hour format then we will write correctly | ||
// const twelveHourClockTime = "08:53 PM"; // Example 12-hour format time | ||
// const twentyFourHourClockTime = "20:53"; // Example 24-hour format time | ||
|
||
const twelveHourClockTime = "08:53 PM"; // Example 12-hour format time | ||
const twentyFourHourClockTime = "20:53"; // Example 24-hour format time | ||
function convertTo12HourClockTime(time24clock) { | ||
let [hours, minutes] = time24clock.split(":").map(Number); | ||
const modifier = hours >= 12 ? "PM" : "AM"; | ||
|
||
if (hours === 0) { | ||
hours = 12; // Midnight case | ||
} else if (hours > 12) { | ||
hours -= 12; // Convert to 12-hour format | ||
} | ||
|
||
return `${hours}:${minutes.toString().padStart(2, "0")} ${modifier}`; | ||
} | ||
function convertTo24HourClockTime(time12clock) { | ||
let [time, modifier] = time12clock.split(" "); | ||
let [hours, minutes] = time.split(":").map(Number); | ||
|
||
if (modifier === "PM" && hours !== 12) { | ||
hours += 12; | ||
} else if (modifier === "AM" && hours === 12) { | ||
hours = 0; | ||
} | ||
|
||
return `${hours.toString().padStart(2, "0")}:${minutes | ||
.toString() | ||
.padStart(2, "0")}`; | ||
} | ||
console.log(convertTo12HourClockTime(twentyFourHourClockTime)); // Output: "08:53 PM" | ||
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. Nice implementation! I don't think this statement outputs exactly "08:53 PM". 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. I checked again the outputs is exactly "08:53 PM". 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 is the code I see in the PR. Is this the function you were testing? function convertTo12HourClockTime(time24clock) {
let [hours, minutes] = time24clock.split(":").map(Number);
const modifier = hours >= 12 ? "PM" : "AM";
if (hours === 0) {
hours = 12; // Midnight case
} else if (hours > 12) {
hours -= 12; // Convert to 12-hour format
}
return `${hours}:${minutes.toString().padStart(2, "0")} ${modifier}`;
} Do you get "08:53 pm" or "8:53 pm" from this function call? |
||
console.log(convertTo24HourClockTime(twelveHourClockTime)); // Output: "20:53" | ||
// Output: "20:53" | ||
// Output: "08:53 PM" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,9 @@ console.log(`£${pounds}.${pence}`); | |
// Try and describe the purpose / rationale behind each step | ||
|
||
// To begin, we can start with | ||
// 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
// 1. const penceString = "399p": initialize a string variable with the value "399p" | ||
//2. Removes the trailing "p" from the string: and result will be 399 | ||
//3. Ensures the number has at least 3 digits by padding from the left with zeros: like 000 | ||
//4. Extracts the pound portion: "3" | ||
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 we expect this program to work as intended for any valid 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. yes, it can work without '.padEnd(2, "0") (line 16) from the code? ' and I tested with different digits and it works 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. You don't have to delete |
||
//5.Extracts the pound portion: "99" | ||
//6. Extracts the pound portion: in the standard monetary format of pounds and pence: "£3.99" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,11 @@ In the Chrome console, | |
invoke the function `alert` with an input string of `"Hello world!"`; | ||
|
||
What effect does calling the `alert` function have? | ||
This displays a popup box (called an "alert dialog") in the browser with the message: 'Hello world!' | ||
|
||
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? | ||
A popup input box appears asking: "What is your name?" | ||
What is the return value of `prompt`? | ||
surafel | ||
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. I think the question is asking, in general, what does 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. corrected 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. What if the user clicked "Cancel"? |
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.
What are these code for? They are not doing anything.
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.
corrected