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

Type of program is designed to be transmitted over the internet and run in a web

ID: 3725283 • Letter: T

Question

Type of program is designed to be transmitted over the internet and run in a web browser

Type of program is designed to be transmitted over the internet and run in a web browser

Type of program is designed to be transmitted over the internet and run in a web browser

Type of program is designed to be transmitted over the internet and run in a web browser

Type of program is designed to be transmitted over the internet and run in a web browser

Type of program is designed to be transmitted over the internet and run in a web browser


Program all problems in one main method. Be sure to document your program and include output that tests your program completely 1. Sum of Numbers Write a program segment that asks the user for a positive non-zero integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 5, the loop will find the sum of 1,2, 3, 4, 5 2. Random Number Guessing Game (17 & 18) Write a program segment that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program segment should use a loop that repeats until the user correctly guesses the random number. Keep a count of how many times it takes to guess the number. The program segment should display the number of guesses the user needed to guess the number. 3. Slot Machine Simulation (21) A slot machine is a gambling device that the user inserts money into and then pulls a lever (or presses a button). The slot machine then displays a set of random images. If two or more of the images match, the user wins an amount of money that the slot machine dispenses back to the user. Create a program that simulates a slot machine. When the program runs, it should do the following Asks the user to enter the amount of money he or she wants to enter into the slot machine. Instead of displaying images, the program will randomly select a word from the following list: .

Explanation / Answer

The following are the solutions to two of the above questions (Q1 & Q2). Both the questions have been coded in Javascript such that they can be "transmitted over the internet and run in a web browser". To execute, just copy paste the code into a text editor, save it as a *.html file and open it using any browser.

Q3 hasnt fully been uploaded and therefore no answer to it can be provided.

Q1. Sum of Numbers

<!DOCTYPE html>
<html>
<title>Sum of numbers</title>
<head>
<script>
function TakeInp() {
var input = prompt("Please enter a positive integer: ");
var ans = 0;
if (input > 0) {
for (i = 1; i <= input; i++) {
ans = ans + i;
}
}
document.write(ans);
}
TakeInp();
</script>
</head>
<body>
</body>
</html>

Q2. Random Number guessing

<!DOCTYPE html>
<html>
<title>Sum of numbers</title>
<head>
<script>
var range = 100;
function GenerateNum()
{
var Guess = Math.ceil(range*Math.random());
return Guess;
}

function TakeInp()
{
var input = prompt("Please Enter a number: ");
return input;
}

function Main()
{
var Guess = GenerateNum();
var tries = 0, flag = 1;
while(flag == 1)
{
var inp = TakeInp();
if(inp == null)
{
document.write("User has chosen to quit ");
document.write("The answer was : "+Guess+" ");
break;
}
tries = tries + 1;
if(inp == Guess)
{
document.write("Correct Guess! ")
document.write("Number of guesses = " + tries + " ");
break;
}
if(Guess < inp)
{
alert("Too high, try again. ");
continue;
}
else if(Guess > inp)
{
alert("Too low, try again. ")
continue;
}
}
}
Main();
</script>
</head>
<body>
</body>
</html>