// 1-100之间的奇数和偶数和
先给两个装和的变量
let odd = 0;
let even = 0;
for (i = 1; i<= 100; i++) {
if (i % 2 === 0) {
赋值
even+=i ;
} else{
odd+=i;
}
}
console.log(‘偶数和‘+`${even}`,‘奇数和‘+`${odd}`);
判断用户输入的数是否是质数
console.log(‘请输入一个数:‘);
let num = readline.question();
let falg = 1;
for (let i = 2; i < num; i++) {
if (num % i ===0) {
console.log(num + ‘不是质数‘);
falgt=0;
break;
}
}
if (falg) {
console.log(num+‘是质数‘);
}
let arr = [[‘a‘, ‘b‘] ,[‘c‘, ‘d‘, ‘e‘,]];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
// 提示用户输入1-7之间任意数,判断并输出是工作日还是休息日。用switch做
console.log(‘请输入1到7之间的任意数‘)
let day = readline.question(‘‘) - 0;
switch (day) {
case 1:
case 2:
case 3:
case 4:
case 5:
console.log(‘工作日‘);
break;
case 6:
console.log(‘休息日‘);
case 7:
console.log(‘休息日‘);
break;
default:
console.log(‘输入有误‘);
}
原文地址:https://www.cnblogs.com/ybzwj/p/9065298.html