Skip to content

Commit 38ee172

Browse files
committed
Add check functions for formatAs12HourClock to validate outputs and error handling
1 parent 6fc17ad commit 38ee172

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎Sprint-3/5-stretch-extend/format-time.js‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,20 @@ function formatAs12HourClock(time){
4040

4141
return `${String(hours12).padStart(2, "0")}:${minutes} ${period}`;
4242
}
43-
console.log(formatAs12HourClock("23:20"))
43+
console.log(formatAs12HourClock("23:20"))
44+
45+
function check(input, targetOutput){
46+
const currentOutput = formatAs12HourClock(input);
47+
console.assert(currentOutput === targetOutput, `input: ${input}. current output: ${currentOutput}, target output: ${targetOutput}`);
48+
}
49+
50+
function checkThrows(input){
51+
let threw = false;
52+
try{
53+
formatAs12HourClock(input);
54+
}
55+
catch(error){
56+
threw = true;
57+
}
58+
console.assert(threw, `input: ${String(input)} should have thrown an error`);
59+
}

0 commit comments

Comments
 (0)