Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Weird, for me JS solution didn't work unless I used BigInt...
Im equavalent to a stone in math, but solved this with math. I think its just comes with more and more practice, I kinda see where you need to use loops and where its better to use math.. Im just playing with numbers and somehow get the result. But im very dumb at math. And very often i need to loop things.
Thank you for the explanation Sir. +1
tl;dr Yes, this is shorthand for declaring two variables with the same value. But this answer is poorly written, as explained below.
= is the assignment operator, which evaluates from right to left. You can imagine that line as
var costA = (n = 0)
the assignment operator also evaluates to the value of whatever was assigned, so n = 0 evaluates to 0. So after assigning to the n variable, the line then becomes
var costA = 0
which of course assigns the value 0 to costA. Note that if later the value of n changes, costA will not match the new value for n. costA will have its own value.
Note that this answer would be considered BAD code in 2022. By both declaring and instantiating the variable n without the var keyword, n defaults to global scope. This means that as soon as the movie() function is run once, the value of n will be visible outside of the function scope, which can lead to silent bugs. Thus, multiple assignment (=) in one line should be done ONLY after the variables being assigned to the right of the first assignment have already been declared. For example:
(within the function)
var n;
var costA = n = 0,
costB = card;
It's still considered poor form to mix and match some declaration and some assignment, as it makes the code harder to glean for bugs. I would instead prefer to declare local variables at the top of the function, because technically that's what the JavaScript interpreter is doing anyways for var declarations (all locally-scoped variables are "hoisted" to the beginnig of the enclosing scope).
(within the function)
var costA, costB, n;
costA = n = 0;
costB = card;
To avoid some of these oddities with var and accidental globals, I instead declare variables with let or const exclusively.
I'm a little confused with what's happening with the var costA line. Are you declaring two variables as 0 at once?
I tried googling it a bit but I wasn't sure what to Google and couldn't find an answer.
Any nudges in the correct direction would be appreciated. =D
This comment is hidden because it contains spoiler information about the solution
Beauty & simple