generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 326
London | 26-ITP-Jan | Oussama Mouggal | Sprint 2 | Acoursework #970
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
Open
Oussama-Mouggal
wants to merge
16
commits into
CodeYourFuture:main
Choose a base branch
from
Oussama-Mouggal:acoursework/sprint-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cb6e13e
predicted the error and generated new code
Oussama-Mouggal c2530c2
predicted the error and generated a new code
Oussama-Mouggal a15ff43
removed double variable declaration inside the function
Oussama-Mouggal dab62aa
modified the function to correctly square a number
Oussama-Mouggal b3a0d25
Update comments to clarify function purpose and expected behavior
Oussama-Mouggal a79905f
Fix sum function to correctly return the sum of two numbers
Oussama-Mouggal 6b1dc06
Fix getLastDigit function to correctly return the last digit of a number
Oussama-Mouggal bf15334
Implement BMI calculation function to return Body Mass Index to 1 dec…
Oussama-Mouggal 61c8f7a
Convert ed a string using convertToUp perCase function
Oussama-Mouggal 632b135
Implement toPounds function that logs different inputs.
Oussama-Mouggal 8c06db1
Answered the questions
Oussama-Mouggal c7167f3
Refactor fixed bugs and tested edge cases
Oussama-Mouggal 759b9c5
Merge branch 'CodeYourFuture:main' into acoursework/sprint-2
Oussama-Mouggal 1e5df86
Delete wget-log
Oussama-Mouggal e522512
fixed the mistakes in 2/2 and 2/5
Oussama-Mouggal 7038fc9
Merge branch 'acoursework/sprint-2' of https://github.com/Oussama-Mou…
Oussama-Mouggal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,22 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============> the code gives an error because there is a variable declaration with the same name as the parameter of the function. | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| let newStr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return newStr; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
|
|
||
| // =============> write your explanation here: The error is occurring because the variable newStr is declared inside the function capitalise, | ||
| // but it is being accessed outside the function. | ||
|
|
||
| // =============> write your new code here: | ||
| function capitalise(str) { | ||
| let newStr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return newStr; | ||
| } | ||
| let newStr = capitalise("hello"); | ||
| console.log(newStr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,28 @@ | ||
| // Predict and explain first... | ||
| // Predict and explain first: Decimalnumber is already declared as a parameter of the function convertToPercentage, | ||
| // so when we try to declare it again inside the function, it will give an error. | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // =============> write your prediction here : The error will occur because we are trying to declare a variable with the same name as the parameter of the function. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
|
|
||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
| console.log(convertToPercentage(0.5)); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here : I removed the variable variation inside the function and directly calculated the percentage. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // =============> write your new code here :function convertToPercentage(decimalNumber) { | ||
|
|
||
| // const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| // return percentage; | ||
| // } | ||
|
|
||
| //console.log(convertToPercentage(0.5)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,23 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
| // Predict and explain first BEFORE you run any code: the function is supposed to return the square of the number. | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // =============> write your prediction of the error here: Maybe because we used a number instead of a variable inside the function declaration. | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| //function square(3) { | ||
| // return num * num; | ||
| // } | ||
|
|
||
| // =============> write the error message here | ||
| // =============> write the error message here : syntax error: Unexpected number (3) | ||
|
|
||
| // =============> explain this error message here | ||
| // =============> explain this error message here: we shouldn't use a number as a parametre name of the function. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| function square(num) { | ||
| return num*num; | ||
| } | ||
| console.log(square(3)); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| // Predict and explain first... | ||
| // Predict and explain first: This function is supposed to multiply two numbers and return the result. | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> write your prediction here : The result will be the multiplication of the two numbers. | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here : The function is logging the result of the console.log statement | ||
| // but it is not returning any value. That's because we are using console.log instead of return in the function. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // =============> write your new code here : | ||
| function multiply(a, b) { | ||
| return a * b; | ||
| } | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============> write your prediction here: The function will not return the sum of a and b because there is a syntax error. | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
| // function sum(a, b) { | ||
| // return; | ||
| // a + b; | ||
| // } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| //console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here : return should be on the same line as a + b. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum (a,b){ | ||
| return a+b; | ||
| } | ||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,30 @@ | ||
| // Predict and explain first... | ||
| // Predict and explain first...: the function is supposed to return the last digit of a number, | ||
| // but it won't because it's using a fixed number instead of a variable to get the last digit from. | ||
|
|
||
| // Predict the output of the following code: | ||
| // =============> Write your prediction here | ||
| // =============> Write your prediction here : it will give the same last digits of the same number (3). | ||
|
|
||
| const num = 103; | ||
| // const num = 103; | ||
|
|
||
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
| // function getLastDigit() { | ||
| // return num.toString().slice(-1); | ||
| // } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
| // console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| // console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| // console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // =============> write the output here | ||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // =============> write the output here : It gave the same last digit for all the numbers, which is 3. | ||
| // Explain why the output is the way it is : because the function is using a fixed number (103) . | ||
| // =============> write your explanation here: because the function is using a fixed number (103) . | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // =============> write your new code here | ||
| function getLastDigit(num) { | ||
| return num.toString().slice(-1);} | ||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
|
||
| // This program should tell the user the last digit of each number. | ||
| // Explain why getLastDigit is not working properly - correct the problem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,43 @@ | ||
| // 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)); | ||
| const minutes = time.slice(3, 5); | ||
|
|
||
| if (hours === 0) { | ||
| return `12:${minutes} am`; | ||
| } | ||
|
|
||
| if (hours === 12) { | ||
| return `12:${minutes} pm`; | ||
| } | ||
|
|
||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| return `${String(hours - 12).padStart(2, "0")}:${minutes} pm`; | ||
| } | ||
|
|
||
| return `${time} am`; | ||
| } | ||
|
|
||
| const currentOutput = formatAs12HourClock("08:00"); | ||
| const targetOutput = "08:00 am"; | ||
| console.assert( | ||
| currentOutput === targetOutput, | ||
| `current output: ${currentOutput}, target output: ${targetOutput}` | ||
| formatAs12HourClock("08:00") === "08:00 am", | ||
| "08:00 should be 08:00 am" | ||
| ); | ||
| console.assert( | ||
| formatAs12HourClock("00:00") === "12:00 am", | ||
| "00:00 should be 12:00 am" | ||
| ); | ||
| console.assert( | ||
| formatAs12HourClock("12:00") === "12:00 pm", | ||
| "12:00 should be 12:00 pm" | ||
| ); | ||
| console.assert( | ||
| formatAs12HourClock("13:45") === "01:45 pm", | ||
| "13:45 should be 01:45 pm" | ||
| ); | ||
|
|
||
| const currentOutput2 = formatAs12HourClock("23:00"); | ||
| const targetOutput2 = "11:00 pm"; | ||
| console.assert( | ||
| currentOutput2 === targetOutput2, | ||
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| formatAs12HourClock("01:30") === "01:30 am", | ||
| "01:30 should be 01:30 am" | ||
| ); | ||
|
|
||
Oussama-Mouggal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.