-
-
Notifications
You must be signed in to change notification settings - Fork 221
London_ITP_Jan2025| Aung_Ye_Kyaw |Module-Structuring-Testing-Data |Coursework/sprint 1 #319
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
Changes from 15 commits
7ce428b
6442b27
b31a592
8f67390
abbe390
03caef7
c8d6e99
da12dc5
713cbf9
2b9bd4e
73fec8d
b352caf
327e641
ee1a81d
0ae808c
5df1edb
fd06577
129e936
bb4ca32
6e92b38
da1d543
2e70c80
a2ee725
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 | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,14 @@ let lastName = "Johnson"; | |||||
// 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 = ``; | ||||||
// declaring variables for each name and take out fist character | ||||||
|
||||||
let fname_initials = `${firstName.charAt(0)}`; | ||||||
|
let fname_initials = `${firstName.charAt(0)}`; | |
let fname_initials = firstName.charAt(0); |
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.
Remove string interpolate.
Outdated
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.
This string will contain exactly one character, so initial
is probably a better than than initials
, which suggests it contains more than one :)
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.
noted and changed as per suggestion . Thank you.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,22 @@ const maximum = 100; | |
|
||
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
|
||
|
||
const step1 = Math.random(); // get random number >=0 & <1 | ||
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 this is a good explanation, breaking it down into steps is really useful, but can you also talk about what the whole thing does, as well as just the separate steps? 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. As a whole thing this program is for testing Operator precedence , in order to know which operation performs fast . I answered as per I understand :) 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. Precedence is one of the things being tested here, but general code understanding is too :) Can you try to also describe this code in terms of the problem? e.g. in the initials exercise you could describe in problem terms we're "Making a string of the first letter of each name" (whereas in programming terms we'd maybe say "We're making variables storing the first character of each name, and then concatenating them together into one variable") 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. We are making a variable storing the result of round down to nearest largest number of the random numbers multiplied by the result of maximum number subtract minimum , after that adding by 1 and then adding with minimum value. |
||
console.log(`The random number is ${step1}`); | ||
|
||
const step2 = (maximum-minimum+1); | ||
console.log(`The second step is ${step2}`); // subsctract (max from min) and add 1 | ||
|
||
const step3 = step1*step2; // random number multiply by the result from step2 | ||
console.log(`The third step is ${step3}`); | ||
|
||
const step4 = Math.floor(step3); // round down the number and return largest or equal to given number | ||
console.log (`The fourth step is ${step4}`); | ||
|
||
const step5 = step4 + minimum //add with the minimun number | ||
console.log (`The final step is ${step5}`); | ||
|
||
// 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 | ||
// It will help to think about the order in which expressions are evaluated | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
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? | ||
|
||
//Ans: comment the 2 lines | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
|
||
const age = 33; | ||
age = age + 1; | ||
|
||
// The error is cause of trying to change the constant variable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
const 24hourClockTime = "08:53"; | ||
|
||
// the error is because of variable naming conversion . The variable names are staring with numbers. | ||
// it should start with letter or underscore or dollar sign. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -12,11 +12,16 @@ 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 | ||
// 2 functions calls are there . Line 7 and 8 | ||
|
||
|
||
// 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? | ||
//Error at Line 5. There are is cause of missing (,) in replace method . It can be fixed by putting (,) between arguments at replace method() | ||
|
||
// c) Identify all the lines that are variable reassignment statements | ||
// Line 4 & 5 | ||
|
||
// d) Identify all the lines that are variable declarations | ||
// Line 1,2,7 & 8 | ||
|
||
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
// Removing the (,) in carPrice string and changing to number in order to get number value. | ||
illicitonion marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const movieLength = 8784; // length of movie in seconds | ||
const movieLength = 100784; // length of movie in seconds | ||
|
||
const remainingSeconds = movieLength % 60; | ||
const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
@@ -12,14 +12,18 @@ 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? | ||
|
||
// 5 | ||
sarawone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// b) How many function calls are there? | ||
|
||
//no function calls | ||
|
||
// c) Using documentation, explain what the expression movieLength % 60 represents | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
// getting the remainder | ||
sarawone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
// substract remaining minutes from total minuts and divided by 60 | ||
sarawone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
// duration will be better | ||
|
||
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
// yes it is working with different values. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,15 @@ const penceStringWithoutTrailingP = penceString.substring( | |
penceString.length - 1 | ||
); | ||
|
||
|
||
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
const pounds = paddedPenceNumberString.substring( | ||
0, | ||
paddedPenceNumberString.length - 2 | ||
); | ||
|
||
console.log (`The result is ${paddedPenceNumberString}`); | ||
|
||
const pence = paddedPenceNumberString | ||
.substring(paddedPenceNumberString.length - 2) | ||
.padEnd(2, "0"); | ||
|
@@ -25,3 +28,7 @@ console.log(`£${pounds}.${pence}`); | |
|
||
// To begin, we can start with | ||
// 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1) : removing p by using substring method. | ||
// 3.const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); : adding 0 to the start from the left side in case of penstring have 2 numbers only | ||
// 4. const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2); : getting the first letter from the string | ||
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. The first letter? What's in the string? Why would we be getting the first letter from it? 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. Getting the first character from the string to get the pound value from the given string penny . |
||
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); // get the last two letter and add zero in case if there is only one letter. |
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? | ||
pop up dialog box with the message "Hello World" and Ok button. | ||
|
||
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? | ||
pop up dialog box with text box to accept user input | ||
|
||
What is the return value of `prompt`? | ||
string is the return value of prompt | ||
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 is returned if the user presses cancel? 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. null value if user press cancel or enter without typing any value in text box. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,17 @@ In this activity, we'll explore some additional concepts that you'll encounter i | |
Open the Chrome devtools Console, type in `console.log` and then hit enter | ||
|
||
What output do you get? | ||
// ƒ log() { [native code] } | ||
|
||
Now enter just `console` in the Console, what output do you get back? | ||
// console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} | ||
|
||
Try also entering `typeof console` | ||
|
||
Answer the following questions: | ||
|
||
What does `console` store? | ||
store data for a while | ||
|
||
|
||
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? | ||
// (.) is for accessing the object's method |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// =============> capitalise the first letter and take out as it from second till end . | ||
|
||
// call the function capitalise with a string input | ||
// interpret the error message and figure out why an error is occurring | ||
|
||
|
||
function capitalise(str) { | ||
let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
let name = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return name; | ||
} | ||
|
||
const Fname = capitalise("sarawone"); | ||
console.log(`The result is ${Fname}`); | ||
|
||
// =============> write your explanation here | ||
// =============> write your new code here | ||
// Ans: the error is cause of assigning the same variable in again in the function (str) | ||
// =============> | ||
// function capitalise(str) { | ||
//let name = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
// return name; | ||
//} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
// Predict and explain first... | ||
// Will get syntax error | ||
|
||
// Why will an error occur when this program runs? | ||
// =============> write your prediction here | ||
// =============> Cause same variable (decimalNumber) is reassign in the function body | ||
|
||
// Try playing computer with the example to work out what is going on | ||
|
||
function convertToPercentage(decimalNumber) { | ||
const decimalNumber = 0.5; | ||
//const decimalNumber = 0.5; | ||
const percentage = `${decimalNumber * 100}%`; | ||
|
||
return percentage; | ||
} | ||
|
||
console.log(decimalNumber); | ||
let number = convertToPercentage(0.5); | ||
console.log(`The result is ${number}`); | ||
|
||
// =============> write your explanation here | ||
|
||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
// =============> | ||
//function convertToPercentage(decimalNumber) | ||
// { | ||
//const percentage = `${decimalNumber * 100}%`; | ||
//return percentage; | ||
//} | ||
//let number = convertToPercentage(0.5); | ||
// console.log(`The result is ${number}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
// Predict and explain first... | ||
|
||
// =============> write your prediction here | ||
// =============> no return in function so it will show error | ||
|
||
function multiply(a, b) { | ||
console.log(a * b); | ||
return a*b; | ||
} | ||
|
||
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
// =============> it shows as undefined | ||
|
||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
// =============> function multiply(a, b) { | ||
//console.log(a * b); | ||
//return a*b; | ||
// } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// =============> I think it will return the input parameter numbers | ||
|
||
function sum(a, b) { | ||
return; | ||
a + b; | ||
return a+b; | ||
} | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
||
// =============> write your explanation here | ||
// =============> it returned undefined , there is not return value assign in the function body. | ||
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
// =============> function sum(a, b) { | ||
// return a+b; | ||
// } |
Uh oh!
There was an error while loading. Please reload this page.