0

i need to check if a boolean is true but i cant use a regular if query because that if query needs to be over the statement, that boolean = true so i can execute a code that NEEDS to be over the statement boolean = true

eingabe = prompt('1 = Addition, 2 = Subtraktion, 3 = Multiplikation, 4 = Division');
if(eingabe === '1' || '2' || '3' || '4') {
    if(eingabe === '1') {
         x = prompt('Bitte geben sie den ersten Summanden ein!');
         y = prompt('Bitte geben sie den zweiten Summanden ein!');
         fX = parseFloat(x);
         fY = parseFloat(y);
         ergebnis = Addition(fX, fY);
         console.log('Die Summe ihrer Addition wurde berechnet und diese ist:', ergebnis);
        statusCalc = true

if statusCalc is true, the first line is to be executed again, i cant just put the first line under the code because it couldnt execute it because it is now under it. i thought about using eventlisteners but apparently that doesnt work.

I ask the question the 2nd time now if you have problems with understanding, ask instead of closing the question

lmao

You can see what i tried up there.

Roaden
  • 1
  • 1
    `if(eingabe === '1' || '2' || '3' || '4')` should be `if([ "1", "2", "3", "4" ].includes(eingabe))`, because otherwise it’s equivalent to `if('4')` which is equivalent to `if(true)`. How were you trying to use event listeners? Are you trying to _loop_ this code as long as `statusCalc` is `true`? Have you tried using a loop? – Sebastian Simon Nov 05 '22 at 10:37

0 Answers0