Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7772625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:55:44+00:00 2026-06-01T16:55:44+00:00

This is a hw assignment. The answer/output I want is correct. I just don’t

  • 0

This is a hw assignment. The answer/output I want is correct. I just don’t understand why. I want the output to be true if the power function matches the number I am checking against. I do get the answer true for these examples, but I don’t understand how this recursive function is working.

In the else of this function, I am saying base * the function itself. what does that even represent? How can base * power(base, exponent - 1); even compute? Shouldn’t it just run in a circle and then finally end?

console.log(power(2,4) === 16);
console.log(power(2,3) === 8);
console.log(power(2,2) === 4);

var power = function(base, exponent) {
    if(exponent === 0) {
        return 1; 
    }
    else {
        return base * power(base, exponent - 1);
    }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:55:45+00:00Added an answer on June 1, 2026 at 4:55 pm

    The function power returns an integer, so when the function returns base * <some_integer> is a perfectly valid expression. The best way to trace these things is with a pen and paper:

    call stack of power(2,4):

    power(2, 4) = 2 * power(2, 3)
    power(2, 3) = 2 * power(2, 2)
    power(2, 2) = 2 * power(2, 1)
    power(2, 1) = 2 * power(2, 0)
    power(2, 0) = 1 <--base case
    

    now all you have to do is substitute the values up the call stack

    power(2, 4) = 2 * 8 = 16
    power(2, 3) = 2 * 4 = 8
    power(2, 2) = 2 * 2 = 4
    power(2, 1) = 2 * 1 = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just took a look at this answer , and I noticed the following
I have written this code as my answer to an assignment I recieved in
I have a graph like this: As part of a homework assignment I want
I want to preface this by saying that this is a homework assignment. I
For this assignment I had to create my own string class. I initially wrote
I swear this assignment will be the end of me, I've been researching this
so we're doing this assignment at Uni and i have a serious craving to
I've been working on this assignment, where I need to read in records and
OK, I have this assignment and I have to prompt the user for data
How to set entire HTML in MSHTML? I am trying using this assignment: (Document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.