为什么数字“10”表示数字“10”。需要使这个JavaScript代码段工作? [英] Why is the number "10" required to make this javascript code snippet work?

查看:48
本文介绍了为什么数字“10”表示数字“10”。需要使这个JavaScript代码段工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var requiredAge = parseInt(提示(输入你的年龄!),10);





if(isNaN(requiredAge)){

console.log(请输入有效数字。);



}否则if(requiredAge< 18){

console.log(你太年轻了。);



}其他{

console.log(你是+ requiredAge +?欢迎!);



}

var requiredAge = parseInt(prompt("Enter your age!"),10);


if (isNaN(requiredAge)) {
console.log("Please enter a valid number.");

} else if (requiredAge < 18) {
console.log("You're too young.");

} else {
console.log("You are " + requiredAge + "? Welcome!");

}

推荐答案

你的谷歌被打破了吗?



如果你搜索parseInt,第一个结果会给你答案:

Is your Google broken?

If you search for "parseInt", the first result gives you the answer:



S yntax




Syntax


parseInt(string, radix);



参数





string
要解析的值。如果string不是字符串,则将其转换为1。字符串中的前导空格将被忽略。
radix
2到36之间的整数,表示上述字符串的基数(数学数字系统中的基数)。为人类常用的十进制数字系统指定10。 始终指定此参数以消除读者混淆并保证可预测的行为。如果未指定基数,则不同的实现会产生不同的结果。



Parameters



string
The value to parse. If string is not a string, then it is converted to one. Leading whitespace in the string is ignored.
radix
An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string. Specify 10 for the decimal numeral system commonly used by humans. Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified.


这篇关于为什么数字“10”表示数字“10”。需要使这个JavaScript代码段工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆