JavaScript样式库

输入账号密码
console.log('请输入账号');
let inputName = rs.question();
let iName = `855`;
if (inputName == iName) {
    console.log(`账号正确`);

    console.log('请输入密码');
    let inputWord = rs.question();
    let iWord = `qws`;
    if (inputWord == iWord) {
        console.log(`密码正确`);
    } else {
        console.log(`密码错误,重新输入`);
    }
} else {
    console.log(`账号错误,重新输入`);
}
判断用户输入的年份是不是闰年
console.log('请输入1000-5000的年份');
let years = rs.question();
//判断输入的是否合法
if (!isNaN(years) && (years >= 1000 && years <= 5000)) {
    //判断是否为闰年
    if ((years % 4 == 0 && years % 100 != 0) || years % 400 == 0) {
        console.log(`${years}闰年`);
    } else {
        console.log(`${years}平年`);
    }
} else {
    console.log(`${years}错误,请重新输入1000-5000的年份`);
}
成绩优秀 及格
console.log('输入一个成绩');
let Socre = rs.question();
 if (Socre >= 85) {
    console.log(`输入的成绩${Socre},优秀!!`);
} else if (Socre >= 75) {
    console.log(`输入的成绩${Socre},良好`);
} else if (Socre >= 65) {
    console.log(`输入的成绩${Socre},及格`);
}else if (Socre < 60) {
    console.log(`输入的成绩${Socre},不及格`);
}
倒序输出用户的一个四位数(例如:1234,输出:4321)
console.log("请输入一个四位数:");
let num = rs.question();
let a = parseInt(num / 1000);
let b = parseInt(num / 100) % 10;
let c = parseInt(num / 10) % 10;
let d = num % 10;
let e = 1000 * d + 100 * c + 10 * b + a;
console.log(e);

判断工作日/休息日
console.log(`1-7判断工作日/休息日`);
let day = rs.question() - 0;

    switch (day) {
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
            console.log(`工作日`);
            break
        case 6:
        case 7:
            console.log(`休息日`);
            break;
            当有不符合case时,
        default:
            console.log(`请输入1-7的数字`);
    }
奇数偶数的和
let z = 0;
let even = 0, odd = 0;
for (let i = 1; i <=1000; i++) {
    z += i;
    if ( i % 2==0) {
        even += i ; 
    } else {
        odd += i;
    }
} console.log(z);
console.log(even,odd);
99乘法表
for (let i = 1; i <= 9; i++) {
   let k = ``;
   for (let j = 1; j <= i; j++) {
      k+=(`${j}*${i}=${i * j}   `);
   }
   console.log(k);//自动换行
}
冒泡排序法

从小到大进行排序

let arr = [2, 5, 54, 576, 846, 48, 955, 64, 1, 29, 74];
for (let index = 0; index < arr.length; index++) {
    for (let j = 0; j < arr.length - index; j++) {
        if (arr[j] > arr[j + 1]) {
            [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]
        }
    }
}
console.log(arr);//[ 1,  2,  5,  29,  48, 54, 64, 74, 576, 846,955]
选择排序

倒叙从大到小进行排序

let arr = [2, 5, 54, 576, 846, 48, 955, 64, 1, 29, 74];
for (let index = 0; index < arr.length-1; index++) {
    for (let j = index+1; j < arr.length; j++) {
        // 每次都会把最大值放在前面
        if (arr[index] < arr[j]) {
            [arr[index], arr[j]] = [arr[j], arr[index]]
        }
    }
}
console.log(arr);//[955, 846, 576, 74, 64, 54, 48, 29, 5, 2, 1]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值