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

Please keep the following to 1 html document: 1. Implement the following functio

ID: 3541206 • Letter: P

Question

Please keep the following to 1 html document:


1. Implement the following functions:

(a) Function Celsius returns the Celsius equivalent of a Fahrenheit temperature, using the calcuation:

C = 5.0 / 9.0 * (F-32);

(b) Function fahrenheit returns the Fahrenheit equvalent of a Celsius temperature, using the calculation

F = 9.0/5.0 * C +32;

(c) Use these functions to write a script that enables the user to enter eigher a Fahrenheit or a Celsius temperature and displays the Celsius or Fahrenheit equivalent. Your HTML5 document should contain two buttons -- one to initiate the conversion from Fahrenheit to Celsius and one to initiate the conversion from Celsius to Fahrenheit.

2. 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.

Explanation / Answer

<!--here is your second programme

remember input should be a valid digit I do not put any restriction on input.

i am assuming user enter a valid input -->

<html>

<head>

<script>

window.onload=init;

function init()

{

var button=document.getElementById("calculate");

button.onclick = startCalculation;

}

function startCalculation()

{

var base = document.getElementById("base").value;

var power = document.getElementById("power").value;

var out = document.getElementById("output");

var result = RecursiveFunc(base,power);

out.innerHTML = result;

}

function RecursiveFunc(base,power)

{

if(power==1)

{

return base;

}

return base*RecursiveFunc(base,power-1);

}

</script>

</head>

<span>Enter Base:</span><input id="base" type="text"/>

<br/>

<span>Enter Power:</span><input id="power" type="text"/>

<br/>

<span>Output:</span><span id="output"></span>

</br>

<input type="button" id="calculate" value="Calculate"/>


</html>