Not sure if that's what you need.
var num1 = parseFloat(window.prompt("Enter a number: "));
var operatorInput = window.prompt(
"Do you want to add, subtract, multiply, or divide?"
);
while (
operatorInput.toLowerCase() != "add" &&
operatorInput.toLowerCase() != "multiply" &&
operatorInput.toLowerCase() != "divide" &&
operatorInput.toLowerCase() != "subtract"
) {
alert("Invalid Input! Please try again");
operatorInput = window.prompt(
"Do you want to add, subtract, multiply, or divide?"
);
}
var num2 = parseFloat(window.prompt("Second Number: "));
var resultWindow = window.open("", "Result Window", "width=200,height=200");
if (operatorInput.toLowerCase() == "add")
resultWindow.document.write(
`<p>${num1 + " " + "+" + " " + num2 + " " + "=" + " " + (num1 + num2)
}</p>`
);
else if (operatorInput.toLowerCase() == "multiply")
resultWindow.document.write(
`<p>${num1 + " " + "*" + " " + num2 + " " + "=" + " " + num1 * num2
}</p>`
);
else if (operatorInput.toLowerCase() == "divide")
resultWindow.document.write(
`<p>${num1 + " " + "/" + " " + num2 + " " + "=" + " " + num1 / num2
}</p>`
);
else
resultWindow.document.write(
`<p>${num1 + " " + "-" + " " + num2 + " " + "=" + " " + (num1 - num2)
}</p>`
);
You should be careful with using new windows to display information, it's not recommended and many browsers now adays automatically blocks these actions and consider them as spam popup windows if they're directly invoked by javascript. If the results are not being shown for you make sure to allow your browser to allow popups from the link you're displaying it from.
alert()would display a pop-up with the message. But that's not what you need. Instead, you require a new window - is that correct?userInputv/soperatorInput, convertingnum1, andnum2tonumbers, declaringnum2outside of theif, preferring to useconstandletinstead ofvar, theifcondition corrected, etc), make it runnable within stack-snippets, and improve it slightly (using template literals, for example).