Javascript Sum, Average, Product, Largest for Three Numbers
Write a script that takes three integers from the user and displays the sum, average, product, smallest and largest of the numbers in an alert dialog.
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Exercise 6.18 Three Digit Math </title>
<script type="text/javascript">
<!--
var firstnum;
var secondnum;
var flag = 0;
firstnum = window.prompt("Enter any Integer Value:");
secondnum = window.prompt("Enter any second Integer Value:");
thirdnum = window.prompt("Enter any third Integer Value:");
var first = parseInt(firstnum);
var second = parseInt(secondnum);
var third = parseInt(thirdnum);
var sum = first + second + third;
var avg = (first + second + third) / 3;
var prod= first * second * third;
if(first>=second && first>=third)
{
if(second>third)
{
window.alert( " SUM: " + sum + "\n Average: " + avg + "\n Product: " + prod + "\n" + third + " is the smallest number" + "\n" + first + " is the largest of all three numbers" );
}
else
{
window.alert( " SUM: " + sum + "\n Average: " + avg + "\n Product: " + prod + "\n" + second + " is the smallest number" + "\n" + first + " is the largest of all three numbers" );
}
}
else if(second>=first && second>=third)
{
if(first>third)
{
window.alert( " SUM: " + sum + "\n Average: " + avg + "\n Product: " + prod + "\n" + third + " is the smallest number" + "\n" + second + " is the largest of all three numbers" );
}
else
{
window.alert( " SUM: " + sum + "\n Average: " + avg + "\n Product: " + prod + "\n" + first + " is the smallest number" + "\n" + second + " is the largest of all three numbers" );
}
}
else if(third>=first && third>=second)
{
if(first>second)
{
window.alert( " SUM: " + sum + "\n Average: " + avg + "\n Product: " + prod + "\n" + second + " is the smallest number" + "\n" + third + " is the largest of all three numbers" );
}
else
{
window.alert( " SUM: " + sum + "\n Average: " + avg + "\n Product: " + prod + "\n" + first + " is the smallest number" + "\n" + third + " is the largest of all three numbers" );
}
}
// -->
</script>
</head>
<body>
</body>
</html>
2 Responses to Javascript Sum, Average, Product, Largest for Three Numbers
Между прочим, лучший способ защитить кого-нибудь от прослушки - задействовать Подавитель сотовых телефонов
Cool story as for me. It would be great to read something more about that theme. The only thing your blog needs is some pictures of some gizmos.
Nickolas Flouee
Cell phone blocker
Something to say?