Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Open
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
4 changes: 2 additions & 2 deletions week-2/debug/0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Predict and explain first...

// instead of console.lon inside the function return a*b
function multiply(a, b) {
console.log(a * b);
return a * b;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
5 changes: 2 additions & 3 deletions week-2/debug/1.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Predict and explain first...

// did not return value truly
function sum(a, b) {
return;
a + b;
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
6 changes: 2 additions & 4 deletions week-2/debug/2.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Predict and explain first...

const num = 103;

function getLastDigit() {
// pass a parameter inside the function so return num.toString().Slice(-1) that takes the last digit for the user
function getLastDigit(num) {
return num.toString().slice(-1);
}

Expand Down
6 changes: 4 additions & 2 deletions week-2/errors/0.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Predict and explain first...
// write down the error you predict will be raised
// the error that I predict is that there is no function call secondly same name variable str used in 2 times
// then call the function capitalise with a string input
// interpret the error message and figure out why it's happening, if your prediction was wrong

function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
let strs = `${str[0].toUpperCase()}${str.slice(1)}`;
return strs;
}
console.log(capitalise("arslan"));
6 changes: 3 additions & 3 deletions week-2/errors/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Predict and explain first...
// Write down the error you predict will be raised
//the error is function call is not write correctly so i correct it
// Why will an error occur when this program runs?
// Play 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);
console.log(convertToPercentage(0.5));
5 changes: 3 additions & 2 deletions week-2/errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Predict and explain first...
// this function should square any number but instead we're going to get an error
// what is happening? How can we fix it?

function square(3) {
// yes i fix it pass a function parameter then call the parameter outside the function
function square(num) {
return num * num;
}
console.log(square(3));


6 changes: 6 additions & 0 deletions week-2/implement/bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
// Given someone's weight in kg and height in metres
// When we call this function with the weight and height
// Then it returns their Body Mass Index to 1 decimal place
function weightBmI(weight,height){
const heightSqu = height * height;
const Bmi = weight/heightSqu;
return Bmi.toFixed(1);
}
console.log(weightBmI(70,1.27));
7 changes: 7 additions & 0 deletions week-2/implement/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@

// Come up with a clear, simple name for the function
// Use the string documentation to help you plan your solution
function uprCaseString(str){
const uprCase =str.toUpperCase();
const uprCaseStringSlash = uprCase.replace(/ /g,"_");
return uprCaseStringSlash;
}
console.log(uprCaseString("hi arslan"))
console.log(uprCaseString("A quick brown fox jump over a lazy dog"));
6 changes: 6 additions & 0 deletions week-2/implement/to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
// Take this code and turn it into a reusable block of code.
// Declare a function called toPounds with an appropriately named parameter.
// Call this function a number of times to check it works for different inputs
function toPound(kilogram){
const pound = kilogram * 2.20462;
return pound;
}
console.log(toPound(1));
console.log(toPound(3));
5 changes: 5 additions & 0 deletions week-2/implement/vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
// Given a number,
// When I call this function with a number
// Then it returns the new price with VAT added on
function Vat(price){
const vatOnPrice = price * 1.2;
return vatOnPrice;
}
console.log(Vat(50));
26 changes: 14 additions & 12 deletions week-2/interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,42 @@ function pad(num) {
}
return num;
}

function formatTimeDisplay(seconds) {
const remainingSeconds = seconds % 60;
console.log(remainingSeconds);
const totalMinutes = (seconds - remainingSeconds) / 60;
console.log(totalMinutes);
const remainingMinutes = totalMinutes % 60;
console.log(remainingMinutes);
const totalHours = (totalMinutes - remainingMinutes) / 60;
console.log(totalHours);
const remainingHours = totalHours % 24;
console.log(remainingHours);

return `${pad(remainingHours)}:${pad(remainingMinutes)}:${pad(
remainingSeconds
)}`;
return `${pad(remainingHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}

console.log(formatTimeDisplay(143));

// You can play computer with this example
// Use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
// to help you answer these questions

//
// Questions

// a) When formatTimeDisplay is called how many times will pad be called?

// pad is called three times on function call once for Minute and second and hour
// Call formatTimeDisplay with an input of 143, now answer the following:

// 00:02:23
// b) What value is assigned to the parameter num when pad is called for the first time?

// first time when call the value is 0
// c) What is the return value of pad when it is called for the first time?

// return 0
// d) What is the value assigned to the parameter num when pad
// remainingSeconds = 143 % 60 results in 23.
// is called for the last time in this program? Explain your answer

// when call the last time value is 23
// e) What is the return value when pad is called
// 00:02:23
// for the last time in this program? Explain your answer

// f) Research an alternative way of padding the numbers in this code.
// Look up the string functions on mdn