= -;
console.log(Вычисляю ${a} ${symbol} ${b})
console.log(a ${symbol} b)
const symbol = "-"; if(symbol === "-") console.log(a-b)
упростить можно? let a = 2; let b = 5; let symbol = "+"; console.log(Вычисляю ${a} ${symbol} ${b}) if (symbol === "-") console.log(a - b) if (symbol === "+") console.log(a + b) if (symbol === "*") console.log(a * b) if (symbol === "/") console.log(a / b)
https://learn.javascript.ru/switch
let a = 2; let b = 5; let symbol = "-"; console.log(Вычисляю ${a} ${symbol} ${b}) // if (symbol === "-") console.log(a - b) // if (symbol === "+") console.log(a + b) // if (symbol === "*") console.log(a * b) // if (symbol === "/") console.log(a / b) switch (symbol) { case "-": console.log(a - b); break; case "+": console.log(a + b); break; case "*": console.log(a * b); break; case "/": console.log(a / b); break; }
eval(a + symbol + b)
ого, вот это спасибо!!!! let a = 2; let b = 5; let symbol = "*"; console.log(Вычисляю ${a} ${symbol} ${b}); console.log(eval(a + symbol + b))
Обсуждают сегодня