-
Notifications
You must be signed in to change notification settings - Fork 21
HW complete #18
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: master
Are you sure you want to change the base?
HW complete #18
Conversation
|
||
console.log(` |
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.
Just a key idea I wanna point out . . . you want to return a string, not console.log()
. .. because that's what line 69 is doing! But, as you can see when you run the program, line 69 logs undefined
because this attack() function does not return any value.
Keep in mind that console.log() is a tool for developers to see their code while they write. But it's far more important to actually be returning the values our functions calculate.
@@ -21,10 +65,12 @@ let attackOrder = [player1, player2]; | |||
let preventInfiniteLoop = 100; | |||
while (player1.health >= 1 && player2.health >= 1 && preventInfiniteLoop > 0) { | |||
const [attackingPlayer, defendingPlayer] = attackOrder; | |||
console.log(attack(attackingPlayer, defendingPlayer, 1, 2)); | |||
// had to update the parameter for variable damage so it could be truely random | |||
console.log(attack(attackingPlayer, defendingPlayer, 1, Math.floor(Math.random() *10))); |
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.
this logs undefined
instead of a string that is returned by the function.
const seattleSaleTax = .0375 | ||
const wholeSalesTax = washingtonSalesTax + seattleSaleTax | ||
|
||
function Receipt(){ |
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.
Remember the good naming conventions, variables and functions ought to always begin with a lowercase letter and use camelCase. By naming this function with a capital R
you might create the impression that is is a Class, not a function.
THANK YOU! | ||
`) | ||
} | ||
Receipt(logReceipt) |
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.
The formatting is really nice, but unfortunately this implementation negates the idea of having a logReceipt()
function. Keep in mind with these starter files that you don't want to change the part that is already there . . . The setup wants to run a function named logReceipt()
that you are tasked with writing, and then give it those provided values.
So a couple lessons here . . . logReceipt()
is meant to be a reusable piece of code that can take any number of given parameters. This is the core of writing functions, being able to use that bit of code over and over again with variable inputs. One key tool that needs to be used is a spread operator, so that it will work if given 1,2,3, or 1000 menu items.
What's happened here instead is making logReceipt()
just a static array, and not a function at all, then getting the desired output with a static, single-purpose function Receipt()
that can only ever do this one job.
Try again, simplify things, and let the boilerplate run logReceipt()
as a function that takes the three objects.
@@ -20,7 +20,21 @@ const getPointsFromResult = function getPointsFromResult(result) { | |||
// including wins, draws, and losses i.e. 'wwdlw' | |||
// Returns total number of points won | |||
|
|||
|
|||
function getTotalPoints(string){ |
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.
Don't overlook the helpers provided. See how the object RESULT_VALUES
and function getPointsFromResult
are here to do some of this work for you?
No description provided.