und das zweite Problem: Wenn ich „ddd“ für die erste Eingabe und „111“ für die zweite Eingabe eingebe und die Taste drücke, wird NaN in der Konsole angezeigt. Ich möchte stattdessen eine Warnung anzeigen. Wie kann ich diese korrigieren?
Code: Select all
function addFunc() {
var x = document.getElementById("num1").value;
var y = document.getElementById("num2").value;
if (typeof x == 'string' || typeof y == 'string') {
var result = parseInt(x) + parseInt(y);
console.log(result);
} else {
alert("Wrong Entry!");
}
}
Code: Select all
ADD