Skip to content

Commit ca8d208

Browse files
author
Enice-Codes
committed
made changes from these excercises
1 parent 5293699 commit ca8d208

3 files changed

Lines changed: 79 additions & 41 deletions

File tree

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
// I predict that the function expression will run a nerro because the are errors in the code .such as the concole.log in line 6.
43

4+
// I predict that the code would fail because "console.log" was misplaced and
5+
// also because console.log doesnt return an value to use elsewhere.
56

6-
function multiply(a, b) {
7-
concole.log( a* b);
87

9-
}
8+
// =============> write your explanation here
109

11-
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
10+
// console.log only prints to the console — it returns undefined.
11+
// Since the template literal needs an actual value, the function
12+
// must use "return" instead of relying on console.log.
1213

13-
// =============> write your explanation here
14-
// console.log prints out information it does not return any varable to its function.hence the syntax error.
15-
// console.log cant read unprovided information.
16-
// Finally, correct the code to fix the problem
1714
// =============> write your new code here
18-
function multiply (a,b){
19-
if (a===10 && b===32){
20-
let result =a * b ;
21-
return result;
22-
}
23-
}
15+
function multiply(a, b) {
16+
let result = a * b;
17+
return result;
18+
}
19+
20+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

Sprint-2/3-mandatory-implement/2-cases.js

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,55 @@
55

66
// Implement a function that:
77

8+
function toUpperSnakeCase(input) {
9+
return input.toUpperCase().split(" ").join("_");
10+
}
11+
12+
813
// Given a string input like "hello there"
914
// When we call this function with the input string
1015
// it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE"
16+
console.assert(
17+
toUpperSnakeCase("hello there") === "HELLO_THERE",
18+
'"hello there" should be "HELLO_THERE"'
19+
);
1120

1221
// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS"
1322

23+
console.assert(
24+
toUpperSnakeCase("lord of the rings") === "LORD_OF_THE_RINGS",
25+
'"lord of the rings" should be "LORD_OF_THE_RINGS"'
26+
);
27+
1428
// You will need to come up with an appropriate name for the function
1529
// Use the MDN string documentation to help you find a solution
1630
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
1731

18-
function touppersneakers (input){
19-
return input.toUpperCase();
20-
}
21-
console.log(touppersneakers("hello there").toUpperCase());//Hello There
22-
console.log(touppersneakers("lord of the rings").toUpperCase()); // LORD_OF_THE_RINGS
23-
console.log(touppersneakers("good morning").toUpperCase()); // GOOD MORNING
32+
console.assert(
33+
toUpperSnakeCase("good morning") === "GOOD_MORNING",
34+
'"good morning" should be "GOOD_MORNING"'
35+
);
36+
37+
// Single word, no spaces at all
38+
console.assert(
39+
toUpperSnakeCase("single") === "SINGLE",
40+
'"single" should be "SINGLE"'
41+
);
42+
43+
// Empty string
44+
console.assert(
45+
toUpperSnakeCase("") === "",
46+
"empty string should stay empty"
47+
);
48+
49+
// Already-uppercase input
50+
console.assert(
51+
toUpperSnakeCase("already UPPER case") === "ALREADY_UPPER_CASE",
52+
'"already UPPER case" should be "ALREADY_UPPER_CASE"'
53+
);
54+
55+
// Multiple consecutive spaces (each becomes its own underscore)
56+
console.assert(
57+
toUpperSnakeCase("multiple spaces") === "MULTIPLE___SPACES",
58+
'"multiple spaces" should be "MULTIPLE___SPACES"'
59+
);
Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// This is the latest solution to the problem from the prep.
22
// Make sure to do the prep before you do the coursework
33
// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find.
4-
;
54
function formatAs12HourClock(time) {
65
const [hourString, minutes] = time.split(":");
7-
const hours = Number(hourString);
6+
const hours = Number(hourString);
7+
8+
const pad = (h) => String(h).padStart(2, "0");
89

910
if (hours === 0) {
1011
return `12:${minutes} am`;
@@ -15,29 +16,27 @@ const hours = Number(hourString);
1516
}
1617

1718
if (hours < 12) {
18-
return `${hours}:${minutes} am`;
19+
return `${pad(hours)}:${minutes} am`;
1920
}
2021

21-
return `${hours - 12}:${minutes} pm`;
22+
return `${pad(hours - 12)}:${minutes} pm`;
2223
}
2324

24-
// Existing tests
25+
// Existing tests (updated to expect zero-padded hours)
2526
console.assert(
26-
formatAs12HourClock("8:00") === "8:00 am",
27-
"8:00 should be 8:00 am"
27+
formatAs12HourClock("08:00") === "08:00 am",
28+
"08:00 should be 08:00 am"
2829
);
2930

3031
console.assert(
3132
formatAs12HourClock("23:00") === "11:00 pm",
3233
"23:00 should be 11:00 pm"
3334
);
3435

35-
// Additional tests
36-
3736
// Midnight
3837
console.assert(
39-
formatAs12HourClock("0:00") === "12:00 am",
40-
"0:00 should be 12:00 am"
38+
formatAs12HourClock("00:00") === "12:00 am",
39+
"00:00 should be 12:00 am"
4140
);
4241

4342
// Noon
@@ -46,16 +45,16 @@ console.assert(
4645
"12:00 should be 12:00 pm"
4746
);
4847

49-
// PM with minutes
48+
// PM with minutes, hour needs padding
5049
console.assert(
51-
formatAs12HourClock("13:30") === "1:30 pm",
52-
"13:30 should be 1:30 pm"
50+
formatAs12HourClock("13:30") === "01:30 pm",
51+
"13:30 should be 01:30 pm"
5352
);
5453

55-
// AM with minutes
54+
// AM with minutes, hour needs padding
5655
console.assert(
57-
formatAs12HourClock("9:45") === "9:45 am",
58-
"9:45 should be 9:45 am"
56+
formatAs12HourClock("09:45") === "09:45 am",
57+
"09:45 should be 09:45 am"
5958
);
6059

6160
// Last minute of the day
@@ -76,8 +75,14 @@ console.assert(
7675
"12:01 should be 12:01 pm"
7776
);
7877

79-
// 1 PM
78+
// 1 PM, hour needs padding
79+
console.assert(
80+
formatAs12HourClock("13:00") === "01:00 pm",
81+
"13:00 should be 01:00 pm"
82+
);
83+
84+
// 1 AM, hour needs padding
8085
console.assert(
81-
formatAs12HourClock("13:00") === "1:00 pm",
82-
"13:00 should be 1:00 pm"
86+
formatAs12HourClock("01:00") === "01:00 am",
87+
"01:00 should be 01:00 am"
8388
);

0 commit comments

Comments
 (0)