First you declare inputtedCommand as undefined:
(首先,您将inputtedCommand声明为undefined:)
var inputtedCommand;
then you try to add it to a number which will always return NaN
(那么您尝试将其添加到将始终返回NaN的数字中)
var inputtedCommand = inputtedCommand + which;
So change it to:
(因此将其更改为:)
var inputtedCommand = 0;
var input = document.getElementById("showInput");
document.addEventListener("keydown", function(e){
console.log(e.which)
console.log(e.key)
var which = e.which
var inputtedCommand = inputtedCommand + which;
console.log(inputtedCommand)
input.innerHTML = "- ", inputtedCommand;
});
and it won't blow up.
(它不会炸毁。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…