I need to create a bit of code for javascript which I can have
random numbers generate with a certain amount of digits set by the
user. and ask the user how many times they want this to
happen.
For example The user says they want a number with 4 digits (any
number between 0 - 9999) and the user can input if they want to
add, subtract, multiply, divide, or make it random
2 random numbers are generated. First number 1451 and the next
number is 58.
If the user selects "random" the program will pick between the 4
(add multiple subtract divide)
Once the numbers are made 1451 & 58 the user then needs to
"add" (random pick) and the profram lets them know if they did it
correct or not.
Say the player select they want to do this 3 times. it just
repeats the process above.
Additionally would it be possible to record the results?
Code -
<!DOCTYPE html>
<html>
<title>Web Page Design</title>
<head>
<script>
var output,num1,num2,operator;
function myFunction() {
var digitCount = parseInt(document.getElementById("digit").value);
var numberRange = Math.pow(10, digitCount)
num1 = Math.floor(Math.random() * (numberRange - 1));
num2 = Math.floor(Math.random() * (numberRange - 1));
var x = parseInt(document.getElementById("mySelect").value);
var choice;
if (x == 6) {
choice = Math.floor(Math.random() * 4) + 2;
}
else {
choice = parseInt(document.getElementById("mySelect").value);
}
operator = getOperator(choice);
document.getElementById("demo").innerHTML = "First number " + num1 + " Second number " + num2 + " your choice " + operator;
}
function getResult() {
output = parseInt(document.getElementById("output").value);
var result = operation(num1,num2,operator);
if(result==output){
document.getElementById("result").innerHTML = "Correct answer";
}
else{
document.getElementById("result").innerHTML = "Wrong answer";
}
}
function operation(num1,num2,operator){
switch (operator) {
case '+': return num1+num2; break;
case '-': return num1-num2; break;
case '*': return num1*num2; break;
case '/': return num1/num2; break;
}
}
function getOperator(choice) {
switch (choice) {
case 2: return '+'; break;
case 3: return '-'; break;
case 4: return '*'; break;
case 5: return '/'; break;
}
}
</script>
</head>
<body>
Enter the number of digits <input type="text" id="digit"><br>
Select the operation you want to perform<select id="mySelect" onchange="myFunction()">
<option value="1">---Default---</option>
<option value="6">Random</option>
<option value="2">Add</option>
<option value="3">Subtract</option>
<option value="4">Multiply</option>
<option value="5">Divide</option>
</select>
<div id="demo"></div>
Your output : <input type="text" id="output">
<input type="button" value="Submit" onclick="getResult()">
<div id="result"></div>
</body>
</html>
Screenshots -




I need to create a bit of code for javascript which I can have random numbers...
Can somebody help me with this assignment. I will highly
appreciate. Also, please display the output as well. I need to use
JAVA to to write the program.
This is the sample output provided by my
professor.
HOME WORK: due 09.17.2019 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor...
Big Numbers Library The creators of C++ have created primitive data types to allow developers to store numbers of various size they expect most users will need. Such as short, int, double. In our case we want to expand on these primitive data types and allow users to store big numbers that can store up to 1,000 digits long. In order to do this, you will create a BigNumbers class, using TDD, Test Driven Development, that will use vectors from...
The creators of C++ have created primitive data types to allow developers to store numbers of various size they expect most users will need. Such as short, int, double. In our case we want to expand on these primitive data types and allow users to store big numbers that can store up to 1,000 digits long. In order to do this, you will create a BigNumbers class that will use vectors from STL to store the digits. BigNumbers should have...
Java Assignment Calculator with methods. My code appears below what I need to correct. What I need to correct is if the user attempts to divide a number by 0, the divide() method is supposed to return Double.NaN, but your divide() method doesn't do this. Instead it does this: public static double divide(double operand1, double operand2) { return operand1 / operand2; } The random method is supposed to return a double within a lower limit and...
Purpose: To familiarize yourself with variables and arithmetic. Directions: Convert the following problems below to c++ equivalent code. Each problem should be done within the same file and all within the same main function. After each step is performed the user should be shown the updated value that was changed. Turn in the finished c++ (.cpp) file for problem 0-6 and the image file for problem 7. Remember to reset or use unique variables for each problem (you cannot declare...
Create a simple calculator. Your interface should contain two input boxes in which the user can put two numbers. There should be four buttons: add, subtract, multiply, and divide. When the user inputs two number and clicks on an operation button, the result should be displayed in the label. Can some please help my code that i came up with just displays a pop box with no words or nothing! I'm not the best at coding. Any tips or advice...
This Java program is giving me a good amount of trouble. Can someone solve this for me and provide explanations? I use BlueJ. Create a class named DLD_JFrame_Arithmetic with a JFrame that accepts two numbers. It is the first time we will use numbers with a JFrame. JTextFields take all inputs as Strings. They must be converted. int num = Integer.parseInt(number.getText()); We will create Three JLabels, two which prompt user to enter numbers in the JTextFields. The third will be for...
I need help with this Java problem, please. Code must be written in Java Create an application that calculates batting statistics for baseball players. Console Welcome to the Batting Average Calculator Enter number of times at bat: 5 0 = out, 1 = single, 2 = double, 3 = triple, 4 = home run Result for at-bat 1: 0 Result for at-bat 2: 1 Result for at-bat 3: 0 Result for at-bat 4: 2 Result for at-bat 5: 3 Batting...
I have Majority of the code written but I just need to implement
the <,>,and = sign in the code. I have posted the
instructions for the whole code. I will add what I have at the
end.
Objectives:
Implement basic class concepts in Java
Implement inheritance with super and sub-classes
Implement basic polymorphism concepts
Problem: The TARDIS has been infected by a virus which means it
is up to Doctor Who to manually enter calculations into the TARDIS
interface....
Assignment:Super Lotto
This exercise is JavaScript only. No jQuery, please. Your page
should work as follows:
Ask the user the highest number that they want to generate. (Some
lotteries are 1 ‐ 47, some 1 ‐ 49, etc.)
Ask the user how many numbers they want to generate.
Create a function that returns a random number between 1 and the
highest number (see "Additional Info" below).
Create an array of numbers. Run the function the correct number
of times, putting...