Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using HTML programming, Write a recursive function power (base, exponent) that,

ID: 3687978 • Letter: U

Question

Using HTML programming,

Write a recursive function power (base, exponent) that, when invoked, returns base exponent. For example, power (3,4)=3 * 3 * 3 *3. Assume that exponent is an integer greater than or equal to 1. The recursion step would use the relationship

baseexponent = base * base exponent -1

and the terminating condition occurs when exponent is equal to 1, because

base1 = base

Incorporate this function into a script that enables the user to enter the base and exponent. the link below is a screen shot of what it should look like:

https://troy.blackboard.com/bbcswebdav/pid-10107205-dt-content-rid-40467041_1/users/xhuan/CS4443_5th/homework/data/homeworkpic.jpg

Explanation / Answer

<HTML>

<HEAD>

<TITLE>Recursive Power Function </TITLE>

<SCRIPT LANGUAGE = "Javascript">

function FindPower() {

var base, exponent;

base = document.RecursivePower.base.value;

exponent = document.RecursivePower.exponent.value;

document.RecursivePower.result.value = Power(base,exponent);

function Power(base,exponent)

{ if (exponent == 1) return base;

else return base*Power(base,exponent-1);

}

}

</SCRIPT>

</HEAD>

<BODY BGCOLOR = "white">

<H2>

This Program asks you for the <EM>base</EM> and the <EM>exponent</EM> and calculates the base raised to the exponent.

<BR>

<FORM NAME = "RecursivePower">

Enter the base:

<INPUT NAME = "base" TYPE = "text" SIZE = "15">

<BR>

Enter the exponent:

<INPUT NAME = "exponent" TYPE = "text" SIZE = "15">

<BR>

<INPUT TYPE = "button" VALUE = "Submit Numbers" SIZE = "20"

ONCLICK = "FindPower()" >

<BR>

Answer:

<INPUT NAME = "result" TYPE = "text" SIZE = "30">

</FORM>

</BODY>

</HTML>

NOTE: The URL requires username and password which I dont know. so, I did the presentation it in my way.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote