I wrote javascript code to solve the following problem >>>
Write a function exponentiate that accepts two arguments:
base (number)
power (number)
Exponentiate should return the result of raising the base by the power. Assume the power argument will always be an integer greater than or equal to zero. Don't forget that any number raised to the 0th power is equal to 1!
function exponentiate (base, power) {
if (power === 0){
return result = 1
}
// while loop
let count = 0
let result = 1;
while (count < power){
result *= base
count += 1
}
return result
}
exponentiate(3, 0)
But I get the following error: ReferenceError: result is not defined
What is wrong with my code?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)