We have to create a currency converter in which the background image changes when a new currency is converted, the box empties once a currency is converted, a window alert is given when letters are put in the box instead of words, and a window alert is given when someone tries to convert when the box is empty.
My html:<!DOCTYPE html>
<html>
<head>
<title>Currency Converter</title>
<script src=”currencyconverter2.js”></script>
</head>
<body onload=”Instructions()”>
<form>
<! Text boxes for input >
<h1>Pounds:
<input type=”radio” name=”Currency” id=”Pounds” onclick = “Life()”>
</h1>
<h1>Mexican Peso:
<input type=”radio” name=”Currency” id=”Peso” onclick = “Life()”>
</h1>
<h1>Japanese Yen:
<input type=”radio” name=”Currency” id=”Yen” onclick = “Life()”>
</h1>
<h1>Canadian Dollar:
<input type=”radio” name=”Currency” id=”Canadian” onclick = “Life()”>
</h1>
<h1>Australian Dollar:
<input type=”radio” name=”Currency” id=”Australian” onclick = “Life()”>
</h1>
<h1>Swiss Franc:
<input type=”radio” name=”Currency” id=”Swiss” onclick = “Life()”>
</h1>
<h1>Euro:
<input type=”radio” name=”Currency” id=”Euro” onclick = “Life()”>
</h1>
<h1>Vietnamese Dong:
<input type=”radio” name=”Currency” id=”Viet” onclick = “Life()”>
</h1>
<h1> US Dollars:<input type=”text” name=”USDollars” id=”USDollars”</h1>
<br>
</form>
<button type=”button” onclick=”Convert()”>Convert!</button>
</body>
My JavaScript:
function Instructions(){
window.alert(“Enter the US Dollar amount to convert. \n Then, choose a currency. \n Finally, click the CONVERT button. \n Click HELP if you need these instructions again”);
}
function Help(){
window.alert(“Enter the US Dollar amount to convert. \n Then, choose a currency. \n Finally, click the CONVERT button. \n Click HELP if you need these instructions again”);
}
function Convert() {
if( isNaN(d)) {window.alert(“NO LETTERS/WORDS. PUT A NUMBER FOR CONVERSION. BOX WILL NOT CLEAR IF THERE IS A LETTER/WORD.”);
return;
if(document.getElementById(“Pounds”).value==””){window.alert(“Please fill in value in box”);
return;
if (document.getElementById(“Pounds”).checked===true) {
var d = document.getElementById(“USDollars”).value;
var g = (d* 0.75);
}
window.alert(d + ” Dollars is “+ g + ” Pound”);
Clearboxes();
}
if( isNaN(d)) {window.alert(“NO LETTERS/WORDS. PUT A NUMBER FOR CONVERSION. BOX WILL NOT CLEAR IF THERE IS A LETTER/WORD.”);
return;
if(document.getElementById(“Peso”).value==””){window.alert(“Please fill in value in box”);
return;
if (document.getElementById(“Peso”).checked===true) {
var d = document.getElementById(“USDollars”).value;
var g = (d* 20.00);
}
window.alert(d + ” Dollars is “+ g + ” Peso”);
Clearboxes();
}
if( isNaN(d)) {window.alert(“NO LETTERS/WORDS. PUT A NUMBER FOR CONVERSION. BOX WILL NOT CLEAR IF THERE IS A LETTER/WORD.”);
return;
if(document.getElementById(“Yen”).value==””){window.alert(“Please fill in value in box”);
return;
if (document.getElementById(“Yen”).checked===true) {
document.body.style.backgroundImage=”url(‘https://i.insider.com/5dcec4227eece55a0f5ce8d6?width=600&format=jpeg&auto=webp’)”;
var d = document.getElementById(“USDollars”).value;
var g = (d* 108.64);
}
window.alert(d + ” Dollars is “+ g + ” Yen”);
Clearboxes();
}
if( isNaN(d)) {window.alert(“NO LETTERS/WORDS. PUT A NUMBER FOR CONVERSION. BOX WILL NOT CLEAR IF THERE IS A LETTER/WORD.”);
return;
if(document.getElementById(“Canadian”).value==””){window.alert(“Please fill in value in box”);
return;
if (document.getElementById(“Canadian”).checked===true) {
var d = document.getElementById(“USDollars”).value;
var g = (d* 1.30);
}
window.alert(d + ” Dollars is “+ g + ” Canadian”);
Clearboxes();
}
if( isNaN(d)) {window.alert(“NO LETTERS/WORDS. PUT A NUMBER FOR CONVERSION. BOX WILL NOT CLEAR IF THERE IS A LETTER/WORD.”);
return;
if(document.getElementById(“Australian”).value==””){window.alert(“Please fill in value in box”);
return;
if (document.getElementById(“Australian”).checked===true) {
var d = document.getElementById(“USDollars”).value;
}
var g = (d* 1.32);
window.alert(d + ” Dollars is “+ g + ” Australian”);
Clearboxes();
}
if( isNaN(d)) {window.alert(“NO LETTERS/WORDS. PUT A NUMBER FOR CONVERSION. BOX WILL NOT CLEAR IF THERE IS A LETTER/WORD.”);
return;
if(document.getElementById(“Swiss”).value==””){window.alert(“Please fill in value in box”);
return;
if (document.getElementById(“Swiss”).checked===true) {
var d = document.getElementById(“USDollars”).value;
var g = (d* 0.98);
}
window.alert(d + ” Dollars is “+ g + ” Swiss”);
Clearboxes();
}
if( isNaN(d)) {window.alert(“NO LETTERS/WORDS. PUT A NUMBER FOR CONVERSION. BOX WILL NOT CLEAR IF THERE IS A LETTER/WORD.”);
return;
if(document.getElementById(“Euro”).value==””){window.alert(“Please fill in value in box”);
return;
if (document.getElementById(“Euro”).checked===true) {
var d = document.getElementById(“USDollars”).value;
var g = (d* 0.86);
}
window.alert(d + ” Dollars is “+ g + ” Euro”);
Clearboxes();
}
if( isNaN(d)) {window.alert(“NO LETTERS/WORDS. PUT A NUMBER FOR CONVERSION. BOX WILL NOT CLEAR IF THERE IS A LETTER/WORD.”);
return;
if(document.getElementById(“Viet”).value==””){window.alert(“Please fill in value in box”);
return;
if (document.getElementById(“Viet”).checked===true) {
var d = document.getElementById(“USDollars”).value;
var g = (d* 22806.50);
}
window.alert(d + ” Dollars is “+ g + ” Viet”);
Clearboxes();
}
}
function Clearboxes() {
document.getElementById(“USDollars”).value=””;
}` `