In this article I would like to share with you a simple program that I wrote using JavaScript to ask the user to give number integer numbers and then our program will swap the arrangement of the two numbers.
I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.
Sample Program Output
Program Listing
index.htm
<!--
Written By Mr. Jake R. Pomperada, MAED-IT
February 6, 2018 04:24 PM Tueday
Bacolod City, Negros Occidental Republic of the Philippines
jakerpomperada@yahoo.com and jakerpomperada@gmail.com -->
<!doctype html>
<html>
<head>
<title> Swap Two Numbers in JavaScript </title>
<style>
.art {
font-family: arial;
font-weight: bold;
color:red;
text-align: center;
width:45%;
background-color:yellow;
}
.art2 {
font-family: arial;
font-weight: bold;
font-size: 25px;
color:blue;
text-align: center;
width:45%;
background-color:lightgreen;
}
body {
font-family: arial;
font-weight: bold;
font-size: 20px;
}
#button_me {
background-color: #008CBA;
font-family: arial;
font-weight: bold;
font-size: 20px;
height: 50px;
width: 120px
text-align: center;
cursor: pointer;
}
input[type=text] {
font-family: arial;
font-weight: bold;
font-size: 20px;
}
</style>
<script>
function swap()
{
var temp;
num1=Number(document.getElementById("val1").value);
num2 =Number(document.getElementById("val2").value);
temp=num1;
num1=num2;
num2=temp;
document.getElementById("result1").value= num1;
document.getElementById("result2").value= num2;
}
</script>
<script>
function clear_me()
{
document.getElementById("val1").value = "";
document.getElementById("val2").value = "";
document.getElementById("val1").focus();
document.getElementById("result1").value= "";
document.getElementById("result2").value= "";
}
</script>
</head>
<body>
<h1 class="art"> Swap Two Numbers in JavaScript </h1>
<p class="art2"> Created By Mr. Jake R. Pomperada, MAED-IT </p>
<br><br>
Value Number 1 <input id="val1" type="text" size="5" autofocus>
<br><br>
Value Number 2 <input id="val2" type="text" size="5">
<br><br>
After Swapping
<br><br>
Value Number 1 <input id="result1" type="text" size="5">
<br><br>
Value Number 2 <input id="result2" type="text" size="5">
<p id="msg"> </p>
<button id="button_me" onclick="swap()">Check</button>
<button id="button_me" onclick="clear_me()">Clear</button>
</br></br>
</body>
</html>
No comments:
Post a Comment