let first = 10;
let last = 5;
let op = '*';
let result = first + op + last;
浏览器拒绝乘法、除法等,我需要在不使用Array的情况下在控制台获取结果,并且数字和乘法需要提示3次
**我尝试的方式**
function getCacl()
{
let firstValue = '';
let op = '';
let lastValue = '';
if(firstValue == ''){
let firstValue = prompt("type number")
if(op == ''){
let op = prompt("type event")
if(lastValue == ''){
let lastValue = prompt("type last number")
let result = (parseInt(firstValue) + op + parseInt(lastValue))
console.log(result );
}
}
}
}
我不明白为什么在函数开头用空字符串初始化变量然后检查它们。每次调用该函数时,变量都会变空。您可以在此处缩短代码。当然,我不是高级 JS 开发人员,但希望我的版本能对您有所帮助。
我会建议这个解决方案......