Skip to content

Commit 1956015

Browse files
committed
Restored Sprint-2 from Main
1 parent 7606c3b commit 1956015

12 files changed

Lines changed: 245 additions & 0 deletions

File tree

Sprint-2/1-key-errors/0.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Predict and explain first...
2+
// =============> write your prediction here
3+
4+
// call the function capitalise with a string input
5+
// interpret the error message and figure out why an error is occurring
6+
7+
function capitalise(str) {
8+
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return str;
10+
}
11+
12+
// =============> write your explanation here
13+
// =============> write your new code here

Sprint-2/1-key-errors/1.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Predict and explain first...
2+
3+
// Why will an error occur when this program runs?
4+
// =============> write your prediction here
5+
6+
// Try playing computer with the example to work out what is going on
7+
8+
function convertToPercentage(decimalNumber) {
9+
const decimalNumber = 0.5;
10+
const percentage = `${decimalNumber * 100}%`;
11+
12+
return percentage;
13+
}
14+
15+
console.log(decimalNumber);
16+
17+
// =============> write your explanation here
18+
19+
// Finally, correct the code to fix the problem
20+
// =============> write your new code here

Sprint-2/1-key-errors/2.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
// Predict and explain first BEFORE you run any code...
3+
4+
// this function should square any number but instead we're going to get an error
5+
6+
// =============> write your prediction of the error here
7+
8+
function square(3) {
9+
return num * num;
10+
}
11+
12+
// =============> write the error message here
13+
14+
// =============> explain this error message here
15+
16+
// Finally, correct the code to fix the problem
17+
18+
// =============> write your new code here
19+
20+

Sprint-2/2-mandatory-debug/0.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Predict and explain first...
2+
3+
// =============> write your prediction here
4+
5+
function multiply(a, b) {
6+
console.log(a * b);
7+
}
8+
9+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10+
11+
// =============> write your explanation here
12+
13+
// Finally, correct the code to fix the problem
14+
// =============> write your new code here

Sprint-2/2-mandatory-debug/1.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Predict and explain first...
2+
// =============> write your prediction here
3+
4+
function sum(a, b) {
5+
return;
6+
a + b;
7+
}
8+
9+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10+
11+
// =============> write your explanation here
12+
// Finally, correct the code to fix the problem
13+
// =============> write your new code here

Sprint-2/2-mandatory-debug/2.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Predict and explain first...
2+
3+
// Predict the output of the following code:
4+
// =============> Write your prediction here
5+
6+
const num = 103;
7+
8+
function getLastDigit() {
9+
return num.toString().slice(-1);
10+
}
11+
12+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15+
16+
// Now run the code and compare the output to your prediction
17+
// =============> write the output here
18+
// Explain why the output is the way it is
19+
// =============> write your explanation here
20+
// Finally, correct the code to fix the problem
21+
// =============> write your new code here
22+
23+
// This program should tell the user the last digit of each number.
24+
// Explain why getLastDigit is not working properly - correct the problem
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Below are the steps for how BMI is calculated
2+
3+
// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.
4+
5+
// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by:
6+
7+
// squaring your height: 1.73 x 1.73 = 2.99
8+
// dividing 70 by 2.99 = 23.41
9+
// Your result will be displayed to 1 decimal place, for example 23.4.
10+
11+
// You will need to implement a function that calculates the BMI of someone based off their weight and height
12+
13+
// Given someone's weight in kg and height in metres
14+
// Then when we call this function with the weight and height
15+
// It should return their Body Mass Index to 1 decimal place
16+
17+
function calculateBMI(weight, height) {
18+
// return the BMI of someone based off their weight and height
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// A set of words can be grouped together in different cases.
2+
3+
// For example, "hello there" in snake case would be written "hello_there"
4+
// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces.
5+
6+
// Implement a function that:
7+
8+
// Given a string input like "hello there"
9+
// When we call this function with the input string
10+
// it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE"
11+
12+
// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS"
13+
14+
// You will need to come up with an appropriate name for the function
15+
// Use the MDN string documentation to help you find a solution
16+
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// In Sprint-1, there is a program written in interpret/to-pounds.js
2+
3+
// You will need to take this code and turn it into a reusable block of code.
4+
// You will need to declare a function called toPounds with an appropriately named parameter.
5+
6+
// You should call this function a number of times to check it works for different inputs
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function pad(num) {
2+
return num.toString().padStart(2, "0");
3+
}
4+
5+
function formatTimeDisplay(seconds) {
6+
const remainingSeconds = seconds % 60;
7+
const totalMinutes = (seconds - remainingSeconds) / 60;
8+
const remainingMinutes = totalMinutes % 60;
9+
const totalHours = (totalMinutes - remainingMinutes) / 60;
10+
11+
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
12+
}
13+
14+
// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
15+
// to help you answer these questions
16+
17+
// Questions
18+
19+
// a) When formatTimeDisplay is called how many times will pad be called?
20+
// =============> write your answer here
21+
22+
// Call formatTimeDisplay with an input of 61, now answer the following:
23+
24+
// b) What is the value assigned to num when pad is called for the first time?
25+
// =============> write your answer here
26+
27+
// c) What is the return value of pad is called for the first time?
28+
// =============> write your answer here
29+
30+
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
31+
// =============> write your answer here
32+
33+
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
34+
// =============> write your answer here

0 commit comments

Comments
 (0)