0% found this document useful (0 votes)
10 views3 pages

Java Script

The document contains code for three JavaScript applications: a currency converter that converts USD to PKR, a distance converter that converts between miles and kilometers, and a basic calculator application that supports addition, subtraction, multiplication and division.

Uploaded by

HABIB Noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Java Script

The document contains code for three JavaScript applications: a currency converter that converts USD to PKR, a distance converter that converts between miles and kilometers, and a basic calculator application that supports addition, subtraction, multiplication and division.

Uploaded by

HABIB Noor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Calculator v1

Currency Converter v1

<html>
<head>
<title>Currency Converter</title>
<script>
function myfx() {
var usd = parseFloat(document.getElementById('txtUSD').value)
var pkr = usd * 276.15;

document.getElementById('mySpan').innerHTML = pkr;
}
</script>
</head>
<body>
<form>
<h3>Currency Converter (USD to PKR)</h3>
<hr /><br /><br />
<label for="txtUSD">US Dollar</label>
<input type="text" id="txtUSD" value="0" />
<input type="button" value="Convert" onclick="myfx()" />
<br />
<label>PK Rupees</label>
<span id="mySpan"></span>
<br />
</form>
</body>
</html>

Distance Converter v2

<html>
<head>
<title>Distance Converter</title>
<script>
function convert(opt) {
var rates;
if (opt == 1)
rates = 1.60934;
else if (opt == 2)
rates = 0.621371;

var txtinput1 = parseFloat(document.getElementById('txtinput1').value)


var result = txtinput1 * rates;

document.getElementById('mySpan').innerHTML = result;
}
</script>
</head>
<body>
<form>
<h3>Distance Converter (Miles to KM)</h3>
<hr /><br /><br />
<label for="txtMiles">Input</label>
<input type="text" id="txtinput1" value="0" /><br />
<input type="button" value="M2KM" onclick="convert(1)" />
<input type="button" value="KM2M" onclick="convert(2)" />
<br />
<label>Result</label>
<span id="mySpan"></span>
<br />
</form>
</body>
</html>

Calculator v2

<html>
<head>
<title>Calculator</title>
<script>
function calc(opt) {
var num1 = parseFloat(document.getElementById('txtNum1').value);
var num2 = parseFloat(document.getElementById('txtNum2').value);
var result = 0;

if (opt == 1)
result = num1 + num2;
else if (opt == 2)
result = num1 - num2;
else if (opt == 3)
result = num1 * num2;
else if (opt == 4)
result = num1 / num2;

document.getElementById('mySpan').innerHTML= result;
}
</script>
</head>
<body>
<form>
<h3>Calculator</h3>
<hr /><br /><br />
<label for="txtMiles">Num1</label>
<input type="text" id="txtNum1" value="0" /><br />

<label for="txtMiles">Num2</label>
<input type="text" id="txtNum2" value="0" /><br />

<input type="button" value="+" onclick="calc(1)" />


<input type="button" value="-" onclick="calc(2)" />
<input type="button" value="*" onclick="calc(3)" />
<input type="button" value="/" onclick="calc(4)" />

<br />
<label>Result</label>
<span id="mySpan"></span>
<br />
</form>
</body>
</html>
Calculator v3

<html>
<head>
<title>Calculator</title>
<script>
function calc(opt) {
var num1 = parseFloat(document.getElementById('txtNum1').value);
var num2 = parseFloat(document.getElementById('txtNum2').value);
var result = 0;

if (opt.value == '+')
result = num1 + num2;
else if (opt.value == '-')
result = num1 - num2;
else if (opt.value == '*')
result = num1 * num2;
else if (opt.value == '/')
result = num1 / num2;

document.getElementById('mySpan').innerHTML= result;
}
</script>
</head>
<body>
<form>
<h3>Calculator</h3>
<hr /><br /><br />
<label for="txtMiles">Num1</label>
<input type="text" id="txtNum1" value="0" /><br />

<label for="txtMiles">Num2</label>
<input type="text" id="txtNum2" value="0" /><br />

<input type="button" value="+" onclick="calc(this)" />


<input type="button" value="-" onclick="calc(this)" />
<input type="button" value="*" onclick="calc(this)" />
<input type="button" value="/" onclick="calc(this)" />

<br />
<label>Result</label>
<span id="mySpan"></span>
<br />
</form>
</body>
</html>

You might also like