Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions Sprint-1/explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Let's try an example.
In the Chrome console,
invoke the function `alert` with an input string of `"Hello world!"`;

What effect does calling the `alert` function have?
What effect does calling the `alert` function have? I get a pop-up window which prints my message.

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?
What is the return value of `prompt`?
What effect does calling the `prompt` function have? I get a pop-up notification asking the question and providing a box to get the input.
What is the return value of `prompt`? it outputs the input of that question.
16 changes: 12 additions & 4 deletions Sprint-1/explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ 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?
What output do you get?
ƒ log() { [native code] }
(log is a function (that's what the ƒ symbol means).
It's a "native" function, meaning it's built into the browser's JavaScript engine)

Now enter just `console` in the Console, what output do you get back?
Now enter just `console` in the Console, what output do you get back?
console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
console is an object.
It contains multiple functions (methods) like debug, error, info, log, warn, etc.

Try also entering `typeof console`
it returns object because console is an object.

Answer the following questions:

What does `console` store?
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
What does `console` store? methods. console is a toolbox full of different tools.
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
The dot tells JavaScript "look inside this object (console) and give me access to this specific method (log or assert)"
8 changes: 7 additions & 1 deletion Sprint-1/interpret/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,17 @@ 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
/*Line 4: Number() replaceAll() | line 5: Number() replaceAll() | line 10: 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?
/*Line 4; lack of comma between "," and ""; add a comma between them. */

// c) Identify all the lines that are variable reassignment statements
/*Line 4, line 5 */

// d) Identify all the lines that are variable declarations
/*Line 1, line 2, line 7, line 8 */

// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
/*firstly, replaceAll string function gets executed. it replaces , in the carPrice variable's value with "". secondly, Number function changes
carPrice's data type from string to numeric. */
21 changes: 19 additions & 2 deletions Sprint-1/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,31 @@ 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?
// a) How many variable declarations are there in this program? 6

// b) How many function calls are there?
// b) How many function calls are there? 1

// c) Using documentation, explain what the expression movieLength % 60 represents
/*it means dividing 8784 by 60 and output the remainder value of this division. */


// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
/*It calculates the movie length in minutes */

// e) What do you think the variable result represents? Can you think of a better name for this variable?
/*it shows how long the movie is in hour/minute/seconds format like 2:34:44 . A better name is: totalMovieLength */

// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer

/*an easier code would be:
const movieLength = 8784;
const totalMovieLength = `${Math.floor(movieLength / 3600)}:${Math.floor((movieLength % 3600) / 60)}:${(movieLength%3600) % 60}`;

Or
const movieLength = 8784;
const hour = Math.floor(movieLength/3600);
const minute = Math.floor((movieLength%3600)/60);
const second = (movieLength%3600)%60;
console.log(`movie length is ${hour}:${minute}:${second}`);
*/

14 changes: 8 additions & 6 deletions Sprint-1/interpret/to-pounds.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
const penceString = "399p";

const penceStringWithoutTrailingP = penceString.substring(
// variable declaration; assignment of value 399p to penceString variable
const penceString = "399p";
// variable declaration; the expression takes the p out of penceString and outputs 399
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

//variable declaration; the expression adds 0 to the start of the penceStringWithoutTrailingP if it has less than 3 characters
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
//variable declaration; the expression takes out 99 from paddedPenceNumberString and outputs 3
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

//variable declaration; the expression takes out 3 from paddedPenceNumberString, then adds 0 to the end of if its characters are less than 2
const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");
.padEnd(2, "0"); //output:99

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

Expand Down