In: Computer Science
Q7: (Currency Conversion) Implement the following double functions: a) Function toAUD takes an amount in US dollars and returns the AUD equivalent. b) Function toYuan takes an amount in US dollars and return the Yuan equivalent c) Use these functions to write a program that prints charts showing the AUD and Yuan equivalents of a range of dollar amounts. Print the outputs in a neat tabular format. Use an exchange rate of 1 USD = 1.42 AUD and 1 USD = 6.793 Yuan. HTML EditorKeyboard Shortcuts
<!DOCTYPE html>
<html>
<head>
<title>
Currency Exchange
</title>
</head>
<body>
<input type = "number" id="audvalue" placeholder="Enter for US Dollars to AUD"/>
<button id="ustoaud" onclick="UStoAUD()">Click here</button><span id="aud"></span> AUD
<br>
<br>
<input type = "number" id="yuanvalue" placeholder="Enter for US Dollars to YUAN"/>
<button id="ustoyuan" onclick="UStoYuan()">Click here</button><span id="yuan"></span> YUAN
<br>
<div><button onclick="generatechart()"> Click to generate table</button></div>
<br>
<table id="chart" border="2px">
<tr>
<th>USD</th>
<TH>AUD</TH>
<TH>YUAN</TH>
</tr>
<tr>
<td id="1"></td>
<td id="2"></td>
<td id="3"></td>
</tr>
<tr>
<td id="4"></td>
<td id="5"></td>
<td id="6"></td>
</tr>
<tr>
<td id="7"></td>
<td id="8"></td>
<td id="9"></td>
</tr>
</table>
</body>
<script>
function UStoAUD(){
var value = document.getElementById("audvalue").value;
document.getElementById("aud").innerHTML = toAUD(value)
}
function toAUD(value){
return 1.42*parseFloat(value);
}
function UStoYuan(){
var value = document.getElementById("yuanvalue").value;
document.getElementById("yuan").innerHTML = toYuan(value)
}
function toYuan(value){
return 6.793*parseFloat(value);
}
function generatechart()
{
var i=0;
for(var j=1;j<=3;j++)
{
document.getElementById(""+(1+(j-1)*3)).innerHTML=j+"";
document.getElementById(""+(2+(j-1)*3)).innerHTML=toAUD(j);
document.getElementById(""+(3+(j-1)*3)).innerHTML=toYuan(j);
}
}
</script>
</html>