Skip to content

Glasgow | ITP May -25 | Pandi Simatupang | Module-Structuring-and-Testing-Data | coursework/sprint-1 #649

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 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3c0525b
add comment on the last line of file 1-count.js
PandiSimatupang Jul 2, 2025
168186a
add console.log() to verify the value of count
PandiSimatupang Jul 2, 2025
72645b8
add function getInitial in 2-initials.js and print to verify
PandiSimatupang Jul 3, 2025
006df3d
solve exercise sprint1/3-paths.js
PandiSimatupang Jul 5, 2025
998a7ee
comment and study exercise sprint-1/4-random.js
PandiSimatupang Jul 5, 2025
63a8de0
solve exec. sprint1/mandatory-errors/0.js
PandiSimatupang Jul 5, 2025
04cb872
study exec. sprint-1/2-mandatory-errors/1.js
PandiSimatupang Jul 5, 2025
55aaa5f
solve exec. sprint-1/2-mandatory-errors/2.js
PandiSimatupang Jul 5, 2025
c1d3745
solve exec. sprint-1/2-mandatory-errors/3.js
PandiSimatupang Jul 5, 2025
a4496e3
solve exec. sprint-1/2-mandatory-errors/4.js
PandiSimatupang Jul 5, 2025
13835fb
solve exec. sprint-1/3-mandatory-interpret/1-percentage-change.js
PandiSimatupang Jul 5, 2025
4bc0b4b
solve exec. sprint-1/3-mandatory-interpret/2.js
PandiSimatupang Jul 5, 2025
e678b92
update solution 2-time-format.js
PandiSimatupang Jul 5, 2025
a5cd1c5
comment out sprint-1/3-mandatory-interpret/3-to-pounds.js
PandiSimatupang Jul 5, 2025
1f7f9e2
tried sprint-1/4-stretch-explore/chrome.md
PandiSimatupang Jul 5, 2025
a8546b9
study and comment out sprint-1/4-mandatory-explore/objects.md
PandiSimatupang Jul 5, 2025
65e1a8e
end of Sprit-1
PandiSimatupang Jul 7, 2025
100b9fd
reset to origin file Sprint-2/1-key-errors/0.js
PandiSimatupang Jul 7, 2025
95efc71
reset file Sprint-2/1-key-errors/1.js
PandiSimatupang Jul 7, 2025
ce9e5c1
reset Sprint-2/1-key-errors/2.js
PandiSimatupang Jul 7, 2025
a638efe
reset file Sprint-2/2-mandatory-debug/0.js
PandiSimatupang Jul 7, 2025
5ae319d
reset file Sprint-2/2-mandatory-debug/1.js
PandiSimatupang Jul 7, 2025
f45625e
reset file Sprint-2/2-mandatory-errors/2.js
PandiSimatupang Jul 7, 2025
d8f561b
reset file Sprint-2/3-mandatory-implement/1-bmi.js
PandiSimatupang Jul 7, 2025
08290c6
reset file Sprint-2/2-mandatory-implement/2-cases.js
PandiSimatupang Jul 7, 2025
3bb0a7c
reset file Sprint-2/2-mandatory-implement/3-to-pounds.js
PandiSimatupang Jul 7, 2025
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
4 changes: 4 additions & 0 deletions Sprint-1/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ count = count + 1;

// Line 1 is a variable declaration, creating the count variable with an initial value of 0
// Describe what line 3 is doing, in particular focus on what = is doing

console.log(`value of count is ${count}`)

// what line 3 doing is add 1 to current value of "count" and saving or assigning the new value (which is 1) as new value
6 changes: 6 additions & 0 deletions Sprint-1/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ let initials = ``;

// https://www.google.com/search?q=get+first+character+of+string+mdn

function getInitial(firstName, middleName, lastName) {
return firstName[0] + middleName[0] + lastName[0];
}

initials = getInitial("Creola", "Katherine", "Johnson");
console.log(`initials is ${initials}`);
10 changes: 7 additions & 3 deletions Sprint-1/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ 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 = ;
const dir = filePath.slice(1, lastSlashIndex);
console.log(dir);

// https://www.google.com/search?q=slice+mdn
const dotIndex = base.lastIndexOf(".");
const ext = base.slice(dotIndex + 1);
console.log(ext);

// https://www.google.com/search?q=slice+mdn
6 changes: 6 additions & 0 deletions Sprint-1/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;

// In this exercise, you will need to work out what num represents?
// Try breaking down the expression and using documentation to explain what it means

//Math.random() -> generates zero base random number
// we need to multiply with digit number needed to allow possible number generated
//Math.floor() method will round up to the base integer generated

// It will help to think about the order in which expressions are evaluated
// Try logging the value of num and running the program several times to build an idea of what the program is doing
console.log(num);
4 changes: 2 additions & 2 deletions Sprint-1/2-mandatory-errors/0.js
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?
3 changes: 3 additions & 0 deletions Sprint-1/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// trying to create an age variable and then reassign the value by 1

//create variable age
const age = 33;

//reassign variable age by 1 (+1)
age = age + 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would not work as we cannot reassign variables declared with const. What other ways can you think of that can allows us to do what we want?

5 changes: 4 additions & 1 deletion Sprint-1/2-mandatory-errors/2.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be aware of the term Hoisting, it would allow us to access variables declared with var before they are assigned. You can read more about it in the link. What you have done is the best approach, and var should be used only when absolutely necessary, but it is worth knowing more about it.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// 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}`);

//it's not working because variable cityOfBirth was not defined.
//change the position of -- const cityOfBirth = "Bolton"; -- before the logging will fix the problem
6 changes: 5 additions & 1 deletion Sprint-1/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const cardNumber = 4533787178994213;
const last4Digits = cardNumber.slice(-4);
const cardNumberStr = cardNumber.toString();
const last4Digits = cardNumberStr.slice(-4);

// 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.
console.log(last4Digits);
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
//can not slice a number, the given card number is integer NOT a List or array
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
//fix by give double quotes to turn the number to sting or make a new variable assign cardNumber.toString()
7 changes: 5 additions & 2 deletions Sprint-1/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
const 12HourClockTime = "20:53";
const 24hourClockTime = "08:53";
const ClockTime_12Hour = "20:53";
const ClockTime_24hour = "08:53";

//variable name convention issues...
//variable name should not started a number
12 changes: 7 additions & 5 deletions Sprint-1/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let carPrice = "10,000";
let priceAfterOneYear = "8,543";

carPrice = Number(carPrice.replaceAll(",", ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));

const priceDifference = carPrice - priceAfterOneYear;
const percentageChange = (priceDifference / carPrice) * 100;
Expand All @@ -12,11 +12,13 @@ console.log(`The percentage change is ${percentageChange}`);
// Read the code and then answer the questions below

// a) How many function calls are there in this file? Write down all the lines where a function call is made

//------->ans: build-in function call line numbers 4,5 and 10
// 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?

//------->ans: error at line 5.
//------->ans: add a missing comma
// c) Identify all the lines that are variable reassignment statements

//------->ans: line 4 (carPrice) and line 5 (priceAfterOneYear)
// d) Identify all the lines that are variable declarations

//------->and: line 1 and 2
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
//------->and: replace character comma with nothing or in other words remove it or delete it
13 changes: 7 additions & 6 deletions Sprint-1/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const movieLength = 8784; // length of movie in seconds
const movieLength = 86401; // length of movie in seconds

const remainingSeconds = movieLength % 60;
const totalMinutes = (movieLength - remainingSeconds) / 60;
Expand All @@ -12,14 +12,15 @@ console.log(result);
// For the piece of code above, read the code and then answer the following questions

// a) How many variable declarations are there in this program?

//------->ans: 6
// b) How many function calls are there?

//------->ans: 1 at the last line, that is console.log() .. it is a built-in function.
// c) Using documentation, explain what the expression movieLength % 60 represents
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

//------->ans: The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?

//------->ans: (movieLength - remainingSeconds) / 60;
// e) What do you think the variable result represents? Can you think of a better name for this variable?

//------->ans: it generates a number in "seconds", for selection of name? the selected one is fine. as long as it follows the variable names convention and the reader or debugger easily understand it.
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
//------->ans: it has a constrain or maybe limitation, that is if value movie length is bigger that 86400 the time shown not appropriate, it should give a hint that it more than a day
15 changes: 10 additions & 5 deletions Sprint-1/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
const penceString = "399p";
const penceString = "9p"; //init variable

const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);
); //remove p character at the end of the variable
console.log(penceStringWithoutTrailingP);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //
console.log(paddedPenceNumberString); //give format of 3 zeroes if the number is less than 3 digits.

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);
); //get ponds value conversion changes for given pence

console.log(pounds);

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
.padEnd(2, "0"); //get the reminds after conversion to pounds

console.log(`£${pounds}.${pence}`);

Expand Down
8 changes: 7 additions & 1 deletion Sprint-1/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Open a new window in Chrome,

then locate the **Console** tab.
then locate the **Console** tab. (short cut for linux ctrl+shift+j)

Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/).
Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it.
Expand All @@ -9,10 +9,16 @@ Let's try an example.

In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;
ans: done!

What effect does calling the `alert` function have?
ans: pops out a message with given strings inside alert arguments

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`.
ans: myname = prompt("What is your name?");

What effect does calling the `prompt` function have?
ans: pops out a message with input field and we can store the input value into a variable

What is the return value of `prompt`?
ans: return value is the string given by user
11 changes: 7 additions & 4 deletions Sprint-1/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course.

Open the Chrome devtools Console, type in `console.log` and then hit enter
ans: done!

What output do you get?

ans: undefined
Now enter just `console` in the Console, what output do you get back?

ans: a list of available methods for console.
Try also entering `typeof console`

ans: done!
Answer the following questions:

ans: object
What does `console` store?
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
ans: console.log() will print given parameter in it,
console.assert(<expression>, <comments>) only print out the given comment if expression inside it is fault or false
6 changes: 2 additions & 4 deletions Sprint-2/1-key-errors/2.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you still need to answer this one!

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// =============> write your prediction of the error here

function square(3) {
return num * num;
return num * num;
}

// =============> write the error message here
Expand All @@ -15,6 +15,4 @@ function square(3) {

// Finally, correct the code to fix the problem

// =============> write your new code here


// =============> write your new code here
4 changes: 2 additions & 2 deletions Sprint-2/3-mandatory-implement/1-bmi.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you still need to answer this one!

Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
// return the BMI of someone based off their weight and height
}