-
-
Notifications
You must be signed in to change notification settings - Fork 51
NW6/Nohe-Tekelmariyam/J1-Modul-week-2 #183
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -15,3 +15,11 @@ | |
|
||
// Come up with a clear, simple name for the function | ||
// Use the string documentation to help you plan your solution | ||
let string = ""; | ||
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. What is the purpose of this line? Where is this variable used? |
||
function upperSnakeCase(string) { | ||
const wordSplit = string.split(" "); | ||
const wordToCapital = wordSplit.map((word) => word.toUpperCase()); | ||
const wordJoin = wordToCapital.join("_"); | ||
return wordJoin; | ||
} | ||
console.log(upperSnakeCase("nohe tekel mariyam")); | ||
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. This solution gets you to the right answer, but there are a few inefficiencies.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,20 @@ | |
// Take this code and turn it into a reusable block of code. | ||
// Declare a function called toPounds with an appropriately named parameter. | ||
// Call this function a number of times to check it works for different inputs | ||
function toPounds(penceString) { | ||
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. Nice work 👍 |
||
const penceStringWithoutTrailingP = penceString.substring( | ||
0, | ||
penceString.length - 1 | ||
); | ||
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
const pounds = paddedPenceNumberString.substring( | ||
0, | ||
paddedPenceNumberString.length - 2 | ||
); | ||
const pence = paddedPenceNumberString | ||
.substring(paddedPenceNumberString.length - 2) | ||
.padEnd(2, "0"); | ||
return `£${pounds}.${pence}`; | ||
} | ||
var penceString = "299p"; | ||
console.log(toPounds(penceString)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,13 @@ | |
// Given a number, | ||
// When I call this function with a number | ||
// Then it returns the new price with VAT added on | ||
function productCostWithVat(price) { | ||
if (typeof price === "number") { | ||
const vatPrice = price * 1.2; | ||
return `£${vatPrice.toFixed(2)}`; | ||
} else { | ||
return "don't waste my time"; | ||
} | ||
} | ||
var price = 399; | ||
console.log(productCostWithVat(price)); | ||
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. This is right ✅ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,25 +19,23 @@ function formatTimeDisplay(seconds) { | |
|
||
console.log(formatTimeDisplay(143)); | ||
|
||
// You can play computer with this example | ||
// Use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit | ||
// to help you answer these questions | ||
|
||
// Questions | ||
|
||
// a) When formatTimeDisplay is called how many times will pad be called? | ||
|
||
//3 time | ||
// Call formatTimeDisplay with an input of 143, now answer the following: | ||
|
||
// b) What value is assigned to the parameter num when pad is called for the first time? | ||
|
||
//remainingHours or 00 | ||
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. 00 would be the returned value of the method as you've correctly identified below. What value will be assigned to the parameter when the function is called? |
||
// c) What is the return value of pad when it is called for the first time? | ||
|
||
//00 | ||
// d) What is the value assigned to the parameter num when pad | ||
// is called for the last time in this program? Explain your answer | ||
|
||
//if second is less than 10 it would add 0 but now it is more than 10 so it return 23. | ||
// e) What is the return value when pad is called | ||
// for the last time in this program? Explain your answer | ||
|
||
// pad return 23 b/c 23 is greater than 10 | ||
// f) Research an alternative way of padding the numbers in this code. | ||
// Look up the string functions on mdn | ||
/ //funtion pad(num) | ||
//{ | ||
// return num.toString().padstart(2,"0"); | ||
//} | ||
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. That's right 👏 |
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.
Great to see you starting to think about input validation 👍