JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<button onclick="myFunction()" id="dif">Difficulty</button>
<p id="demo">here</p>
<p id="test"></p>
<script>
</script>
</body>
JavaScript
document.getElementById('dif').addEventListener('click',myFunction,false); /*we can't use onclick="myFunction()" on this website, so I used event listener. it is not relevant to your problem..*/
function myFunction() {
function shuffle(o){ //try this shuffle function
for(var j, g, t = o.length; t; j = Math.floor(Math.random() * t), g = o[--t], o[t] = o[j], o[j] = g);
return o;
};
var i; var l; var y; var n;
var newx; var newy;
var useranswer; var amountX; var largest;
var copyAmountX;
var mixAlot;
var x = parseInt(prompt("What is the first number?"+" "+"(up to 12)"));
if (x < 13) {
y = parseInt(prompt("what is the second number?"+" "+"(choose up to 12)")); //**you forgot "parseInt" here
n = prompt("how many problems to be solved?"); //**you forgot "parseInt" here
amountX = []; //**you forgot ";"
// adds to an array equal to x (user input)
if (!amountX.length) {
for (var s = 0; s <= x; s++) {
amountX.push(s);
}
};
// just to let me know if it is working. Will be taken out.
alert(amountX);
largest = Math.max.apply(Math, amountX);
alert(largest);
alert(isNaN(x));
}
else {
alert("Refresh page and restart with numbers under 12")
};
if (y > 12 == true) { //**don't use "== true" if you don't need to
alert("Refresh page and restart with numbers under 12")
};
i = 0;
l = amountX.length;
copyAmountX = amountX;
//**For this to work "newx" has to be outside the loop. and since "newy" and "i" are indentical I will only use "i"
newx = shuffle(copyAmountX);
// where the core magic of everything happens.
while (x < 13 && y < 13 && i<n) { //**you don't need to check if x and y are less than 13, because you don't use them in the while loop
useranswer = parseInt(prompt("Multiply "+newx+" by "+i)); //**you forgot "parseInt" here....