如果数字是空的,找到空数字并不能说是正确的

时间:2019-06-17 17:36:35

标签: javascript numbers

我正在编写一个程序,以查明一个数字是否有空(它至少长3位,并且可以由其第一位和最后一位形成的数字整除)。它工作正常,但当我输入一个我知道是空缺的数字时除外。它说不是。这是我的代码:

var num = prompt("Enter a number to see if it is gapful.");
var str = num.toString(1);
var firstnum = str.charAt(0);
var lastnum = str.charAt(str.length - 1);
var firstandlast = firstnum + lastnum;
var check = num % Number(firstandlast);
function yesno() {
    if (str.length < 3) {
        document.write("No; it is less than 3 digits long.");
        return;
    }
    else {
        if (check = 0) {
            document.write("Yes; it is at least 3 digits long and evenly divisible by the number formed by its first and last digits.");
            return;
        }
        else {
            document.write("No; it is at least 3 digits long, however it is not divisible by the number formed by its first and last digits.");
        }
    }
}
yesno();

为什么这行不通?预先谢谢你。

0 个答案:

没有答案