I want (for example my prompt is enter a calculation) if the user enters 2+2 the document.write(sum); should display 4 on my empty page. I know how to easily do this with 2 prompts but im trying to make a sort of calculator. Ive seen this done on google or math way where you can type long strings of numbers and operators then it gives you the steps and finally the answer. I need a way to retrieve 1st item, then 2nd item, then 3rd item then store them in a variable. it would be great if i can do like 22+22 eventually but not sure how that would work. userInput.includes("+") might be good enough because theirs no other time.
//if (userInput.includes(allNumbers && "+")){
// value1 = userInput.split("").map(parseInt).filter(i =>!isNaN(i))[0]
//value2 = parseint(userInput);
// sum = value1 + value1;
//document.write(sum);
//}
I have tried this but when i type 2+2 nothing happens. ive tried looking all over the internet but all i see is all string inputs or 1 number then a 2nd prmpt for the 2nd number.
I expect when a user types 2+2 for document.write to display 4. then i eventually want to do subtraction , division, and multiplication. but at the moment 2+2 does nothing