Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This question is from Principle of Internet Programming(php) subject. Question 1

ID: 3908781 • Letter: T

Question

This question is from Principle of Internet Programming(php) subject.

Question 1.

a) [Javascript] Receive number from user input where it must be between 10 and 100, when it is out-of-range force user to re enter.List out every number that is divisible by 2 and 10 from 1 to select number.

b) [php]Receive two numbers from HTML form (via GET method),then list out the even numbers and total sum of all even numbers in between them.Error checking need to be included,where starting value must be less than ending value and the ending value must not exceed 100.

Explanation / Answer

1a)

<!DOCTYPE html>

<html>

<head>

</head>

<body>

<div>Enter number: <input type="text" id="inp_num" /></div>

<div><input type="submit" value="Generate Numbers"/></div>

<h2>The numbers which are divisible by 2 and 10 are:</h2>

<div id="result"></div>

<script type="text/javascript">

function generate(){

var inp_num = document.getElementById("inp_num").value;

if(inp_num>10 && inp_num<100){

var nums = [];

for(var i=1; i<inp_num; i++){

if(i%2==0 && i%10==0)

nums.push(i);

}

document.getElementById("result").innerHTML = nums;

}

else{

alert("Invalid Number! it must be between 10 and 100");

document.getElementById("inp_num").focus();

}

}

</script>

</body>

</html>

1b)

<?php

if(isset($_GET['num1']) && isset($_GET['num2'])){

$num1 = $_GET['num1'];

$num2 = $_GET['num2'];

if($num1>$num2){

echo "num2 must be greaterthan num1<br />";

}

else if($num2>100){

echo "num2 must not be execeed 100<br />";

}

else{

echo "Even numbers between $num1 and $num2 are: <br />";

$sum = 0;

for($i=$num1; $i<$num2; $i++){

if($i%2==0){

echo $i;

$sum += $i;

}

}

echo "Total sum of even values is: ".$sum."<br />";

}

}

else{

echo "You must pass two values through GET parameter<br />Example: sum.php?num1=3&num2=5"

}

?>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote