I have two sections of my code, each generate a random equation with two numbers and an operation. Example: 28=16 ------ 2(randomized number) "" (randomized operation symbol) 8 (randomized number) = 16 (result). One section of the code is to add and subtract, the other is to multiply and divide. I want to only display one of these options on the website (either add and subtract or multiply and divide). How can I choose to display only one of this two RANDOMLY. Here is the code.
'''
////////////add & subctract
const firstNumber = ((Math.random()*(10000))-5000).toFixed(2);
const secondNumber = ((Math.random()*(10000))-5000).toFixed(2);
const operations = ["+", "-"];
const randomOperation = operations[Math.floor(Math.random() * Math.floor(2))];
const expression = firstNumber + randomOperation + secondNumber;
const resultNotInterger = eval(expression);
const result = parseInt(resultNotInterger);
////////////multiply and divide
const firstNumber = ((Math.random()*(1000))-500);
const secondNumber = ((Math.random()*(1000))-500);
const operations = ["*", "/"];
const randomOperation = operations[Math.floor(Math.random() * Math.floor(2))];
const expression = firstNumber + randomOperation + secondNumber;
const resultNotInterger = eval(expression);
const result = parseInt(resultNotInterger);
///this is my nodeJS in case you wanted to see it.
app.get("/", function(request, response){
response.render("index.ejs", {
firstNumber: firstNumber,
secondNumber: secondNumber,
randomOperation: randomOperation,
result: result
});
});
'''
Aucun commentaire:
Enregistrer un commentaire