Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED]Cubic Minefield: Javascript

Where real men cried.

function power(number, exponent) {
    var total = 1;
while (power > 0) {
        total += number;
        power--;
    }
    return total;
}

What bothers me is that the answer is probably so simple, but I have no idea what code to put.

Think about math! while doing powers, do you multiply or add? What should you minus? Power or total?

Wait where is this level? tell me so i can find it and work things out

Okay, i found the level

Alright, um… Sans…

so to calculate the algorithm, you need to change the power variable to the exponent variable (since that’s what you’re basing it from). and them multiply the total with the number. as well as assigning it to the total variable (multiply and assign).

to multiply variables in a code, you use this ( * ) key

hope this helps
Riley

hi @mayro, the times function above adds the number to the function, and you could also write it as

total = total + number

now try to change the symbol to something that powers do …

This is the error. Put this instead:

total = total * number;

Does it work now? :face_with_raised_eyebrow:

it does, i was trying to make him figure it out, but anyway, yes, it does :rofl:

1 Like

Dear All Big Brains of the Discourse,
I appreciate the help, but it took me some time to admit that I still can’t comprehend what you mean at all… YET. Could you explain in simpler terms?
Sincerely,
NutDealer

Wait a minute…
oh my gosh. I just realized how simple it was. I literally spent a day on this.

2 Likes

There you should multiply number with himself for exponent times and you will get a number that it is in total.
For example, if number=2 and exponent=3, then total=222=8. Do you understand now?

have ou finished the level?

1 Like

I think so… So have you finished the level, @mayro?

yes (20 characterssss)

1 Like

Congratulations then! :partying_face:

1 Like