jeudi 29 juillet 2021

What mistake am I doing in my javascript code?

In the place of "math", user will write name of mathematical operation. I am trying to get user input and want to do user specified mathematical operation on selector 1 and selector 2. Is this js code perfect for that?

self.math = function(math, sel1, sel2){
        let inner = 0;
        switch (inner)
        {
          case (math = 'add') :
             text = sel1 + sel2;
            break;
          case (math = 'multiply') :
             text = sel2 * sel1;
            break;
          case (math = 'subtract') :
             text = sel1 - sel2;
            break;
          case (math = 'subReverse') :
             text = sel2 - sel1;
            break;
          case (math = 'div') :
             text = sel1 / sel2;
            break;
          case (math = 'divReverse') :
             text = sel2 / sel1;
            break;
        }
       self.innerText = text;
       return self;
    }

Aucun commentaire:

Enregistrer un commentaire