Skip to content

LONDON |ITP-MAY-2025| KHILOLARUSTAMOVA | Coursework/sprint1 #588

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@ const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
//Removes the trailing "p" from the string to isolate the numeric part.


const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
//Ensures the numeric string is at least 3 characters long by padding it with leading zeroes if necessary.

const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

//Extracts the pounds part from the padded string.Takes all but the last two digits to represent whole pounds.
//"399" → "3"
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
// Extracts the last two digits to represent the pence (fractional part).
// "399" → "99"

console.log(`£${pounds}.${pence}`);
// Formats and prints the final price in pounds and pence with a currency symbol.
// For "399p", output is: £3.99

// This program takes a string representing a price in pence
// The program then builds up a string representing the price in pounds
Expand All @@ -25,3 +34,6 @@ console.log(`£${pounds}.${pence}`);

// To begin, we can start with
// 1. const penceString = "399p": initialises a string variable with the value "399p"

//Removes the trailing "p" from the string to isolate the numeric part.