QUESTION 1. Write JavaScript program that ask the user for two numbers , adds them up and return the result to the user 2. Improve the question 1 so that it also does subtraction , multiplication and division on the two numbers , calculate the average calculation on 5 numbers and make new line for every operation 3. Write a program that will ask the user for his or her first name , last name , and middle initial . Return then back in the order of last name , first name and middle initial , then in the first name , middle initial and last name format 4. Please do 2 people in one group
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
QUESTION
1. Write JavaScript program that ask the user for two numbers , adds them up and return
the result to the user
2. Improve the question 1 so that it also does subtraction , multiplication and division on the
two numbers , calculate the average calculation on 5 numbers and make new line for
every operation
3. Write a program that will ask the user for his or her first name , last name , and middle
initial . Return then back in the order of last name , first name and middle initial , then in
the first name , middle initial and last name format
4. Please do 2 people in one group
ANSWER
1. Write JavaScript program that ask the user for two numbers , adds them up and return
the result to the user
<!-- This code was designed by
NOOR MELLISA BT AZLAN - D20072030862
MOHD NUR EZUAN BIN MOHD KHUSRIN - D20061026891
Write JavaScript program that ask the user for two numbers , adds them up and return the
result to the user-->
<html>
<head>
<title>~: ADDING TWO NUMBERS :~</title>
<style type="text/css"> /*USING EMBEDDED STYLE*/
/*PAGE BACKGROUND*/
body
{
background-image:url(../../../cam_love.jpg);
background-color:#FFCC66;
background-attachment:fixed;
background-position:center;
background-repeat:no-repeat;
}
/*TITLE <H1>*/
h1
{
font-family:"20.000 dollar bail";
font-size:17px;
margin-top:32px;
margin-left:350;
text-decoration:underline;
}
/*TITLE <H2>*/
h2
{
font-family:"20.000 dollar bail";
font-size:17px;
margin-left:310;
text-decoration:underline;
}
/*TITLE <H3>*/
h3
{
font-family:"20.000 dollar bail";
font-size:18px;
margin-left:300;
text-decoration:underline;
}
/*FOR THE OUTPUT*/
p
{
font-family:"20.000 dollar bail";
font-size:30px;
margin-left:350;
}
/*END OF EMBEDDED STYLE*/
</style>
<script language="javascript">
<!--HIDE
var firstnumber;
var secondnumber;
var total;
-->
</script>
</head>
<body> <!-- REFER TO PAGE BACKGROUND-->
<h1>JavaScript program that ask </h1> <!-- REFER TO H1-->
<h2>the user for two numbers adds them</h2> <!-- REFER TO H2-->
<h3>up and return the result to the user</h3> <!-- REFER TO H3-->
firstnumber=window.prompt("ENTER FIRST INTEGER", "");
<!-- ASK USER TO ENTER FIRST NUMBER-->
secondnumber=window.prompt("ENTER SECOND INTEGER", "");
<!-- ASK USER TO ENTER SECOND NUMBER-->
number1=parseInt(firstnumber);
number2=parseInt(secondnumber);
total = number1 + number2;
document.write("<p>");
document.write("<br>");
document.write("\nTotal addition = " +total); <!-- OUTPUT TOTAL OF TWO NUMBER-->
document.write("</p>");
</script>
</body>
</html>
VIEW IN MOZILLA FIREFOX
1)
2)
3)
2. Improve the question 1 so that it also does subtraction , multiplication and division on the
two numbers , calculate the average calculation on 5 numbers and make new line for
every operation
<!-- This code was designed by NOOR MELLISA BT AZLAN - D20072030862 MOHD NUR EZUAN BIN MOHD KHUSRIN - D20061026891 Improve the question 1 so that it also does subtraction , multiplication and division on the two numbers , calculate the average calculation on 5 numbers and make new line for every operation--> <html> <head> <title>~: MATHEMATICS OPERATION :~</title> <style type="text/css"> /*USING EMBEDDED STYLE*/ /*PAGE BACKGROUND*/ body { background-image:url(../../../math.jpg); background-color:#FF66FF; background-attachment:fixed; background-position:center; background-repeat:no-repeat; } /*TITLE <H1>*/ h1 { font-family:Caduceus; font-size:17px; margin-top:32px; text-align:center; color:#FFFFFF; text-decoration:overline; } /*TITLE <H2>*/ h2 { font-family:Caduceus;
font-size:17px; text-align:center; color:#FFFFFF; text-decoration:overline; } /*TITLE <H3>*/ h3 { font-family:Caduceus; font-size:18px; text-align:center; color:#FFFFFF; text-decoration:overline; } </style> <SCRIPT language="JavaScript"> <!--HIDE var firstnumber; var secondnumber; var thirdnumber; var fourthnumber; var fifthnumber; var total; var fulltotal; //--> </SCRIPT> </HEAD> <BODY> <!-- REFER TO PAGE BACKGROUND--> <h1>Using subtraction , multiplication and division on the </h1> <!-- REFER TO H1--> <h2>two numbers, calculate the average calculation </h2> <!-- REFER TO H2--> <h3>on 5 numbers and make new line for every operation</h3> <!-- REFER TO H3--> <SCRIPT language="JavaScript"> <!-- JAVASCRIPT START--> window.alert("~~PLEASE ENTER ALL THE NUMBER IN THE BOX~~"); <!-- ASK USER TO ENTER FIRST NUMBER--> function addition() <!-- ADDITION--> { firstnumber=document.kira.firstnumber.value;
secondnumber=document.kira.secondnumber.value; number1=parseInt(firstnumber); number2=parseInt(secondnumber); total=number1+number2; //window.alert("Hasil Tambah ialah " + total); var total2= +number1+ "+" +number2+ "=" +total+ "\n"; return total2; } function substraction() <!-- SUBTRACTION--> { firstnumber2=document.kira.firstnumber2.value; secondnumber2=document.kira.secondnumber2.value; number1=parseInt(firstnumber2); number2=parseInt(secondnumber2); total=number1-number2; //window.alert("Hasil Tambah ialah " + total); var total2= +number1+ "-" +number2+ "=" +total+ "\n"; return total2; } function multiplication() <!-- MULTIPLICATION--> { firstnumber3=document.kira.firstnumber3.value; secondnumber3=document.kira.secondnumber3.value; number1=parseInt(firstnumber3); number2=parseInt(secondnumber3); total=number1*number2; //window.alert("Hasil Tambah ialah " + total); var total2= +number1+ "x" +number2+ "=" +total+ "\n"; return total2; } function division() <!-- DIVISION--> { firstnumber4=document.kira.firstnumber4.value; secondnumber4=document.kira.secondnumber4.value; number1=parseInt(firstnumber4); number2=parseInt(secondnumber4); total=number1/number2; //window.alert("Hasil Tambah ialah " + total); var total2= +number1+ "/" +number2+ "=" +total+ "\n"; return total2; }
3. Write a program that will ask the user for his or her first name , last name , and middle
initial . Return then back in the order of last name , first name and middle initial , then in
the first name , middle initial and last name format
<!-- This code was designed by NOOR MELLISA BT AZLAN - D20072030862 MOHD NUR EZUAN BIN MOHD KHUSRIN - D20061026891 Write a program that will ask the user for his or her first name , last name , and middle initial . Return then back in the order of last name , first name and middle initial , then in the first name , middle initial and last name format--> <html> <head> <title>~: NAME :~</title> <style type="text/css"> /*USING EMBEDDED STYLE*/ /*PAGE BACKGROUND*/ body { background-image:url(../../../Downloads/yellow.jpg); background-color:#663333; background-attachment:fixed; background-position:center; background-repeat:no-repeat; } /*OUTPUT*/ h1 { font-family:Caduceus; margin-top:100px; color:#FFFFFF; } /*TABLE STYLE*/ .style1 {font-family: Caduceus; color:#FFFFFF;} .style2 {color: #FFFFFF} .style3 {font-family: Caduceus; color: #FFFFFF; } </style>
<body > <SCRIPT language="JavaScript"> <!-- JAVASCRIPT START--> <!--hide window.alert("~~PLEASE ENTER YOUR NAME~~"); var firstname= prompt('~Please enter your first name~,', ' '); <!-- ASK USER TO ENTER FIRST NAME--> var lastname= prompt('~Please enter your last name~,', ' '); <!-- ASK USER TO ENTER LAST NAME--> var middlename= prompt('~Please enter your middle name~,', ' '); <!-- ASK USER TO ENTER MIDDLE NAME--> //--> </SCRIPT> </head> <body> <div align="center"> <SCRIPT language="javascript"> <!--hide document.write("<center><H1>Hello, <br> "+firstname+" "+middlename+" "+lastname+" <br> Welcome To My Page! <br></h1></Center>"); <!-- OUTPUT--> //--> </SCRIPT> </p> </div> <table width="331" border="1" align="center" bordercolor="#FFFF00"> <tr> <td width="147"><div align="center" class="style3"><strong>Last Name </strong></div></td> <td width="168"><div align="center" class="style1"> <script language="javascript"> document.write(lastname); </script> </div></td> </tr> <tr> <td><div align="center" class="style3"><strong>First Name </strong></div></td>