<script>
let type=+prompt('请输入您要选择的汽油类型:92/95')
let oil=+prompt('周五特惠,请输入您要加油的数量(升)');
if (`${type}==92`) {
console.log(`92号汽油优惠后价格为${oil*6.78}元`);
} else {
console.log(`95号汽油优惠后价格为${oil*7.28}元`);
}
</script>
<script>
let a=+prompt('请输入第1个数字:');
let b=+prompt('请输入第2个数字:');
let c=+prompt('请输入第3个数字:');
let max=a;
if (b>max) {
max=b;
}
if (c>max) {
max=c;
}
console.log('最大值为:'+max);
</script>
<script>
let age=+prompt('请输入您的年龄:');
// 根据年龄判断是否可以查看
if (age >= 18) {
alert("您已满18岁,可以查看.");
} else if (age < 10) {
alert("您未满10岁,不允许查看.");
} else {
let confirm = prompt("您已满10岁,是否继续查看?(yes/no)");
if (confirm == "yes") {
alert("您可以选择继续查看.");
} else {
alert("您选择了不继续查看.");
}
}
</script>
<script>
let year=prompt('请输入您的工作权限:');
let salary=+prompt('请输入您的月收入:');
if (year>=1&&year<2) {
if (salary>=8000&&salary<10000) {
console.log(`年终奖为${salary*1.2+salary}`);
}else if(salary>=10000){
console.log(`年终奖为${salary*1.5+salary}`);
}else{
console.log(`年终奖为${salary+salary}`);
}
}
if (year>=2&&year<3) {
if (salary>=10000&&salary<15000) {
console.log(`年终奖为${salary*1.5+salary}`);
}else if(salary>=10000){
console.log(`年终奖为${salary*1.8+salary}`);
}else{
console.log(`年终奖为${salary+salary}`);
}
}
if (year>=3) {
if (salary>=15000&&salary<20000) {
console.log(`年终奖为${salary*1.8+salary}`);
}else if(salary>=10000){
console.log(`年终奖为${salary*2.5+salary}`);
}else{
console.log(`年终奖为${salary+salary}`);
}
}
</script>
<script>
let year=+prompt('请输入年份:');
if (year%4==0&&year%100!=0||year%400==0) {
console.log(`${year}是闰年`);
} else {
console.log(`${year}是平年`);
}
</script>
5-7点 早上好
7-11点 上午好,祝您心情愉快
11-13点 中午好
13-17点 下午好
17-21点 晚上好
21-23点 夜深了,注意身体哟
其它情况 凌晨了,该休息了
<script>
function getGreeting() {
let now = new Date(); //获取当前的日期
let hours = now.getHours(); //获取当前的时间
let str;
if (hours>=5&&hours<7) {
str='早上好';
} else if (hours>=7&&hours<11) {
str='上午好,祝您心情愉快';
} else if (hours>=11&&hours<13) {
str='中午好';
} else if (hours>=13&&hours<17) {
str='下午好';
} else if (hours>=17&&hours<21) {
str='晚上好';
} else if (hours>=21&&hours<23) {
str='夜深了,注意身体哟';
} else{
str='凌晨了,该休息了';
}
return str;
}
console.log(getGreeting());
</script>
<script>
let salary=+prompt('请输入您的工资:');
let wuxian=salary>7662?7662*0.225:salary*0.225;
let KouChuBZ=prompt('请输入扣除标准: 3500 5000');
let suoDeE=salary-wuxian-KouChuBZ;
let shuiLv=0;
let KouChushu=0;
if (suoDeE<0) {
alert('您不用交税');
}else{
if (suoDeE<=1500) {
shuiLv=0.03;
KouChushu=0;
}else if (suoDeE<=4500) {
shuiLv=0.1;
KouChushu=105;
}else if (suoDeE<=9000) {
shuiLv=0.2;
KouChushu=555;
}else if (suoDeE<35000) {
shuiLv=0.25;
KouChushu=1005;
}else if (suoDeE<=55000) {
shuiLv=0.3;
KouChushu=2755;
}else if (souDeE<=80000) {
shuiLv=0.35;
KouChushu=5505;
}else if (suoDeE>80000) {
shuiLv=0.45;
KouChushu=13505;
}
}
let getShui=suoDeE*shuiLv-KouChushu ;
alert('您要交的个税是'+getShui.toFixed(2)+'元');
</script>
<script>
// 定义出拳函数
function throwDice(player, computer) {
return player === computer ? '平局' : (player > computer ? '玩家胜' : '电脑胜');
}
// 主游戏逻辑
function playGame() {
let playerThrow = Math.floor(Math.random() * 3) + 1; // 玩家出拳:1-3
let computerThrow = Math.floor(Math.random() * 3) + 1; // 电脑出拳:1-3
let result = throwDice(playerThrow, computerThrow); // 判断胜负
console.log(`玩家出拳:${playerThrow}`);
console.log(`电脑出拳:${computerThrow}`);
console.log(`本次对决结果:${result}`);
let playerWins = 0, computerWins = 0;
while (playerWins < 2 && computerWins < 2) { // 当双方胜利次数都少于2次时,继续游戏
result = throwDice(playerThrow, computerThrow); // 再次出拳并判断胜负
if (result === '玩家胜') playerWins++; // 玩家胜利,胜利次数加1
else if (result === '电脑胜') computerWins++; // 电脑胜利,胜利次数加1
}
if (playerWins > computerWins) console.log('玩家胜利!'); // 输出最终胜者
else if (computerWins > playerWins) console.log('电脑胜利!'); // 输出最终胜者
else console.log('平局!'); // 平局情况,双方胜利次数相等
}
// 开始游戏
playGame();
</script>
<script>
for (let i = 200; i < 300; i++) {
let number = i.toString().split('');
if(number.length===3&&number[0]*number[1]*number[2]===42&&parseInt(number[0])+parseInt(number[1])+parseInt(number[2])===12) {
console.log(i);
}
}
</script>
<script>
for (let r = 0; r <= 28; r++) {
for (let w = 0; w <= 31; w++) {
let b = 31 - w;
if (r + w === 25 && w + b === 31 && r + b === 28) {
console.log(`红球数量: ${r}`);
console.log(`白球数量: ${w}`);
console.log(`黑球数量: ${b}`);
break;
}
}
}
</script>
<script>
let initialWatermelons = 1020;
let daysNeeded = 0;
while (initialWatermelons > 0) {
// 第一天卖一半多两个
let sold = Math.floor(initialWatermelons / 2) + 2;
// 剩余的西瓜数量
initialWatermelons = initialWatermelons - sold;
// 增加一天
daysNeeded++;
}
console.log(`需要${daysNeeded}天才能卖完所有的西瓜。`);
</script>