-
-
Notifications
You must be signed in to change notification settings - Fork 390
Cape Town |ITP-MAY-26|Enice Mutanda|Sprint 2| Coursework #1400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b610fbe
fc76e95
f4d4ae5
23a6152
26dd684
bfe65da
5293699
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,23 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // when running the code there will be a syntax error because the `str` being a function name has already been declared | ||
| // so it cant be returned .so the return variable should have another name | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
| //Uncaught SyntaxError: Identifier 'str' has already been declared | ||
|
|
||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // there is an error in the code because the `str` is declared twice and there are unexpected token '}'. | ||
|
|
||
| // =============> write your new code here | ||
| function capitalise (str) { | ||
| return `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,26 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // the will be an error when this code runs because the retrun varaible has not been assigined by a value and there function has not declared a variable. | ||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // synch equation | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| // =============> write the error message here | ||
| // Uncaught SyntaxError: Unexpected number | ||
| // > return num * num; | ||
| // return num * num; | ||
|
|
||
| // =============> explain this error message here | ||
| //Uncaught SyntaxError: Illegal return statement | ||
|
|
||
| // =============> explain this error message here | ||
| // the error is simply saying that the return variable has not been assigned by a value.`illegal statement`. | ||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square (num){ | ||
| return num * num; | ||
| } | ||
| console.log (square(3)) // 9 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,23 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // 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. | ||
|
|
||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| concole.log( a* b); | ||
|
|
||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // console.log prints out information it does not return any varable to its function.hence the syntax error. | ||
| // console.log cant read unprovided information. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply (a,b){ | ||
| if (a===10 && b===32){ | ||
| let result =a * b ; | ||
| return result; | ||
| } | ||
| } | ||
|
cjyuan marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,10 @@ | |
| // You will need to come up with an appropriate name for the function | ||
| // Use the MDN string documentation to help you find a solution | ||
| // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
|
|
||
| function touppersneakers (input){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you look up the naming conventions in JavaScript? In particular,
Then, update the function name according to those conventions. |
||
| return input.toUpperCase(); | ||
| } | ||
|
Comment on lines
+17
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| console.log(touppersneakers("hello there").toUpperCase());//Hello There | ||
| console.log(touppersneakers("lord of the rings").toUpperCase()); // LORD_OF_THE_RINGS | ||
| console.log(touppersneakers("good morning").toUpperCase()); // GOOD MORNING | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,83 @@ | ||
| // This is the latest solution to the problem from the prep. | ||
| // Make sure to do the prep before you do the coursework | ||
| // 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. | ||
|
|
||
| ; | ||
| function formatAs12HourClock(time) { | ||
| const hours = Number(time.slice(0, 2)); | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| const [hourString, minutes] = time.split(":"); | ||
| const hours = Number(hourString); | ||
|
|
||
| if (hours === 0) { | ||
| return `12:${minutes} am`; | ||
| } | ||
|
|
||
| if (hours === 12) { | ||
| return `12:${minutes} pm`; | ||
| } | ||
| return `${time} am`; | ||
|
|
||
| if (hours < 12) { | ||
| return `${hours}:${minutes} am`; | ||
| } | ||
|
|
||
| return `${hours - 12}:${minutes} pm`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
| const targetOutput = "08:00 am"; | ||
| // Existing tests | ||
| console.assert( | ||
| formatAs12HourClock("8:00") === "8:00 am", | ||
| "8:00 should be 8:00 am" | ||
| ); | ||
|
Comment on lines
-13
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original tests suggest the argument is a string in the form "hh:mm" (2-digit hour and 2-digit minute). Without changing the argument, to make the return value formatted consistently we could conditionally pad a |
||
|
|
||
| console.assert( | ||
| formatAs12HourClock("23:00") === "11:00 pm", | ||
| "23:00 should be 11:00 pm" | ||
| ); | ||
|
|
||
| // Additional tests | ||
|
|
||
| // Midnight | ||
| console.assert( | ||
| currentOutput === targetOutput, | ||
| `current output: ${currentOutput}, target output: ${targetOutput}` | ||
| formatAs12HourClock("0:00") === "12:00 am", | ||
| "0:00 should be 12:00 am" | ||
| ); | ||
|
|
||
| const currentOutput2 = formatAs12HourClock("23:00"); | ||
| const targetOutput2 = "11:00 pm"; | ||
| // Noon | ||
| console.assert( | ||
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| formatAs12HourClock("12:00") === "12:00 pm", | ||
| "12:00 should be 12:00 pm" | ||
| ); | ||
|
|
||
| // PM with minutes | ||
| console.assert( | ||
| formatAs12HourClock("13:30") === "1:30 pm", | ||
| "13:30 should be 1:30 pm" | ||
| ); | ||
|
|
||
| // AM with minutes | ||
| console.assert( | ||
| formatAs12HourClock("9:45") === "9:45 am", | ||
| "9:45 should be 9:45 am" | ||
| ); | ||
|
|
||
| // Last minute of the day | ||
| console.assert( | ||
| formatAs12HourClock("23:59") === "11:59 pm", | ||
| "23:59 should be 11:59 pm" | ||
| ); | ||
|
|
||
| // One minute after midnight | ||
| console.assert( | ||
| formatAs12HourClock("00:01") === "12:01 am", | ||
| "00:01 should be 12:01 am" | ||
| ); | ||
|
|
||
| // One minute after noon | ||
| console.assert( | ||
| formatAs12HourClock("12:01") === "12:01 pm", | ||
| "12:01 should be 12:01 pm" | ||
| ); | ||
|
|
||
| // 1 PM | ||
| console.assert( | ||
| formatAs12HourClock("13:00") === "1:00 pm", | ||
| "13:00 should be 1:00 pm" | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why check if the parameters
aandbare these particular values?