Skip to content

Commit 632f5be

Browse files
committed
I made changes based on review
1 parent 433e170 commit 632f5be

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
// Predict and explain first...
2-
// Missing backticks for template string template strings need to use backticks `, but here ${} is used without them
2+
/// This code will error before it runs. 'str' has already been declared"
3+
//
4+
// This happens because:
5+
// 1. 'str' is already declared as a function parameter
6+
// 2. Inside the function, we try to declare 'str' again using 'let'
7+
8+
// original code
9+
//function capitalise(str) {
10+
//let str = `${str[0].toUpperCase()}${str.slice(1)}`;
11+
//return str;
12+
//}
313

4-
// call the function capitalise with a string input (error)
5-
// interpret the error message and figure out why an error is occurring
6-
// ${} must be inside backticks and str is being redeclared (it is already the function parameter)
14+
// write your explanation here
15+
//When you write: function capitalize(str)
16+
// - 'str' is already declared as a parameter
17+
//Then inside the function: let str = ...
18+
// - This tries to declare 'str' again
719

8-
9-
// =============> write your explanation here
10-
// =============> This function takes a string and returns a new string with the first letter in capital
20+
// new code
1121
function capitalise(str) {
12-
return `${str[0].toUpperCase()}${str.slice(1)}`;
13-
}
22+
let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`;
23+
return capitalised;
24+
}
25+
26+
console.log(capitalise("hello")); // "Hello"
27+
28+

Sprint-2/5-stretch-extend/format-time.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ function formatAs12HourClockFixed(time) {
4949
return `${time.slice(0, 5)} am`;
5050
}
5151

52+
console.log("=== Test for fixed function ===\n");
53+
54+
console.log(formatAs12HourClockFixed("00:00"), "→ Expected: 12:00 am");
55+
console.log(formatAs12HourClockFixed("00:30"), "→ Expected: 12:30 am");
56+
console.log(formatAs12HourClockFixed("01:00"), "→ Expected: 01:00 am");
57+
console.log(formatAs12HourClockFixed("08:15"), "→ Expected: 08:15 am");
58+
console.log(formatAs12HourClockFixed("11:59"), "→ Expected: 11:59 am");
59+
console.log(formatAs12HourClockFixed("12:00"), "→ Expected: 12:00 pm");
60+
console.log(formatAs12HourClockFixed("12:30"), "→ Expected: 12:30 pm");
61+
console.log(formatAs12HourClockFixed("13:00"), "→ Expected: 01:00 pm");
62+
console.log(formatAs12HourClockFixed("14:45"), "→ Expected: 02:45 pm");
63+
console.log(formatAs12HourClockFixed("23:59"), "→ Expected: 11:59 pm");

0 commit comments

Comments
 (0)