Tuesday, September 22, 2020

Swapping Two Numbers in JavaScript

I will show you how to write a JavaScript program to ask two numbers and then the program will swap the arrangement of the two numbers. 

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking and Arduino Project development at a very affordable price.

Program Listing

index.htm

<!DOCTYPE html>
<html>
<head>
<script>
function swapping(){
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c=a;
a=b;
b=c;
document.getElementById("answer1").value= a;
document.getElementById("answer2").value= b;
}

function clear_all(){
document.getElementById("first").value= "";
document.getElementById("second").value= "";
document.getElementById("answer1").value= "";
document.getElementById("answer2").value= "";
document.getElementById("first").focus();
}
</script>
<style>
body {
font-family: arial;
size : 15px;
};
</style>
</head>
<body>
<h2> Swapping Two Numbers in JavaScript </h2>
<h3> Before Swapping of Two Numbers </h3>
Give First Value  : <input id="first" 
onkeypress="return event.charCode >= 48 && event.charCode <= 57">
Give Second Value : <input id="second" 
onkeypress="return event.charCode >= 48 && event.charCode <= 57"></br></br>
<button onclick="swapping()">Swap</button>
&nbsp;&nbsp;
<button onclick="clear_all()">Clear</button></br></br>
<h3> After Swapping of Two Numbers </h3>
Give First  Value  : <input id="answer1"
onkeypress="return event.charCode >= 48 && event.charCode <= 57" readonly>
Give Second Value  :  <input id="answer2"
onkeypress="return event.charCode >= 48 && event.charCode <= 57" readonly>
</body>
</html>

No comments:

Post a Comment