This question has already been answered:
- Create function Calculator JavaScript 4 Responses
How to make it so that the variable Z displays the result of mathematical operations, and not just a string.
Here is the code:
var z = 0; var operat = ['+', '-']; var rand1 = operat[Math.floor(Math.random() * operat.length)]; var rand2 = operat[Math.floor(Math.random() * operat.length)]; var reZ1 = Math.floor(Math.random() * (10 - 1 + 1)) + 1; var reZ2 = Math.floor(Math.random() * (10 - 1 + 1)) + 1; console.log(reZ1, reZ2); z = z + rand1 + reZ1 + rand2 + reZ2; console.log(z);