当前位置:网站首页>js小练习
js小练习
2022-07-07 03:22:00 【鹿蹊zz】
目录
1.用户输入一个数字,判定数字是奇数还是偶数,如果不是数字也要给出提示
2.判定两个数字之间的最大值(用户输入两个数字,判定哪个数字大)
6.出租车,起步价(2公里以内)为7元,超过2公里的按照每公里3元计算。要求根据路程计算费用
7.判断闰年(闰年的条件是能被4整除,但不能被100整除;或能被400整除。)
8.根据性别和体重计算输血量。女性体重不超过50kg的输血量为200毫升,否则250毫升;男性体重不超过60kg的输血量为250毫升,否则300毫升.
9.当气温高于26℃时,需要开启制冷空调;气温低于10℃则开启制热空调;其余情况只需要开启送风模式即可。编制自动温控程序,控制操作用输出相应的提示字符串来模拟,比如“开启制冷”
1.用户输入一个数字,判定数字是奇数还是偶数,如果不是数字也要给出提示
var num = prompt("请输入一个整数")*1;
if (num % 2 == 0) {
document.write(num+"偶数");
} else {
document.write(num+"奇数");
}
2.判定两个数字之间的最大值(用户输入两个数字,判定哪个数字大)
var str1 = prompt("请输入数字1")*1;
var str2 = prompt("请输入数字2")*1;
if (str1 > str2) {
document.write("最大的数是" + str1);
} else {
document.write("最大的数是" + str2);
}
3.成绩等级的判定
var grade = prompt("请输入你的成绩") * 1;
if (grade >= 90) {
document.write("优秀");
} else if (grade >= 80) {
document.write("良好");
} else if (grade >= 70) {
document.write("一般");
} else if (grade >= 60) {
document.write("及格");
} else {
document.write("不及格");
}
4.用户输入一个年份,判定该年份有多少天
var year = prompt("请输入年份") * 1;
if ((year%4==0&&year%100!=0) || year%400==0){
document.write(year+"年有366天");
}else{
document.write(year+"年有365天");
}
5.制定学习计划表,输入星期几,能提示今天要学习什么课程
var day = prompt("请输入今天星期几:");
if (day > 0 && day <= 7) {
switch (day) {
case "1":
document.write("今天星期一,要学习语文");
break;
case "2":
document.write("今天星期二,要学习数学");
break;
case "3":
document.write("今天星期三,要学习英语");
break;
case "4":
document.write("今天星期四,要学习物理");
break;
case "5":
document.write("今天星期五,要学习化学");
break;
case "6":
document.write("今天星期六,要睡懒觉");
break;
default:
document.write("今天星期日,要休息");
break;
}
} else {
alert("一周只有7天!!!");
}
6.出租车,起步价(2公里以内)为7元,超过2公里的按照每公里3元计算。要求根据路程计算费用
var km = prompt("请输入公里数:");
// var sum;
if (km > 0 && km <= 2) {
document.write("本次行程费用为7元");
} else if(km>2){
sum = 7 + (km - 2) * 3;
document.write("本次行程费用为" + sum + "元");
}else{
document.write("花钱是不可能的!!!");
}
7.判断闰年(闰年的条件是能被4整除,但不能被100整除;或能被400整除。)
var year = prompt('请输入年份') * 1;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
document.write(year + "年是闰年");
} else {
document.write(year + "不是闰年");
}
8.根据性别和体重计算输血量。女性体重不超过50kg的输血量为200毫升,否则250毫升;男性体重不超过60kg的输血量为250毫升,否则300毫升.
var a = prompt("请输入您的性别");
var b = prompt("请输入您的体重");
if (a == "女") {
if (b <= 50) {
document.write("您的输血量为200毫升");
} else {
document.write("您的输血量为250毫升");
}
} else if (a == "男") {
if (b <= 60) {
document.write("您的输血量为250毫升");
} else {
document.write("您的输血量为300毫升");
}
} else {
document.write("请输入正确性别");
}
9.当气温高于26℃时,需要开启制冷空调;气温低于10℃则开启制热空调;其余情况只需要开启送风模式即可。编制自动温控程序,控制操作用输出相应的提示字符串来模拟,比如“开启制冷”
var temperature = prompt("请输入当前的气温:(℃)");
if (temperature > 26) {
document.write("开启制冷!");
} else if (temperature < 10) {
document.write("开启制热!");
} else {
document.write("开启送风!");
}
10.根据《省电网销售电价表》,居民生活用电按3个梯度收费:月用电量150千瓦时及以下部分,每千瓦时0.4463元,151—400千瓦时部分为0.4663元,401千瓦时以上部分为0.5663元, 请编写程序,当输入用户的用电量时,计算出所需付的费用。
var a = prompt("请输入月用电量(千瓦):");
var price;
if (a > 0 && a <= 150) {
price = a * 0.4463;
document.write("您需要支付的电费为" + price + "元。");
} else if (a > 150 && a <= 400) {
price = (a - 150) * 0.4663 + 150 * 0.4463;
document.write("您需要支付的电费为" + price + "元。");
} else {
price = (a - 400) * 0.5663 + 250 * 0.4663 + 150 * 0.4463;
document.write("您需要支付的电费为" + price + "元。");
}
11.假设从A地到B地的火车票有硬座和硬卧,价格分别为100和190元。 根据铁路部门规定,未成年人(18周岁以下)身高不足120cm免票,120(含)-150(不含)cm需半票,150及以上的需全票,未成年人卧铺只能减免硬座的半价。请设计一个购票程序,要求输入年龄和身高(未成人需要输入)以及票的类型,输出票的价。
var age = prompt('请输入年龄')*1;
var tick = prompt('请输入票型');
if(age>=18){
if(tick=='硬座'){
document.write("100");
}else{
document.write("190");
}
}else{
var height = prompt('请输入身高')*1;
if(height<120){
document.write("免费");
}else if(height<150){
if(tick=='硬座'){
document.write("50")
}else{
document.write("140");//这里是未成年人身高120-150买的硬卧票 190-50(硬座的半价)
}
}else{
if(tick=='硬座'){
document.write("100")
}else{
document.write("190");
}
}
}
12.输出两个数字之间的最大数
var str1 = prompt("请输入数字1");
var str2 = prompt("请输入数字2");
if (str1 > str2) {
document.write("最大的数是" + str1);
} else {
document.write("最大的数是" + str2);
}
边栏推荐
- Jetpack compose is much more than a UI framework~
- How can gyms improve their competitiveness?
- Common function detect_ image/predict
- 2018 Jiangsu Vocational College skills competition vocational group "information security management and evaluation" competition assignment
- 化工园区危化品企业安全风险智能化管控平台建设四大目标
- 算法---比特位计数(Kotlin)
- 【mysqld】Can't create/write to file
- SolidWorks GB Library (steel profile library, including aluminum profile, aluminum tube and other structures) installation and use tutorial (generating aluminum profile as an example)
- 基于JS的迷宫小游戏
- 使用TCP/IP四层模型进行网络传输的基本流程
猜你喜欢
[noi simulation] regional division (conclusion, structure)
Can 7-day zero foundation prove HCIA? Huawei certification system learning path sharing
Implementation of AVL tree
化工园区危化品企业安全风险智能化管控平台建设四大目标
Special behavior of main function in import statement
How to do sports training in venues?
CompletableFuture使用详解
健身房如何提高竞争力?
LVS+Keepalived(DR模式)学习笔记
Release notes of JMeter version 5.5
随机推荐
. Net 5 fluentftp connection FTP failure problem: this operation is only allowed using a successfully authenticated context
联合索引ABC的几种索引利用情况
main函数在import语句中的特殊行为
数据资产管理与数据安全国内外最新趋势
组件的嵌套和拆分
AVL树的实现
Comment les entreprises gèrent - elles les données? Partager les leçons tirées des quatre aspects de la gouvernance des données
$refs:组件中获取元素对象或者子组件实例:
Matlab tips (30) nonlinear fitting lsqcurefit
剑指offer-高质量的代码
【mysqld】Can't create/write to file
【mysqld】Can't create/write to file
sql中对集合进行非空校验
从零到一,教你搭建「CLIP 以文搜图」搜索服务(二):5 分钟实现原型
企業如何進行數據治理?分享數據治理4個方面的經驗總結
MySQL user permissions
工具类:对象转map 驼峰转下划线 下划线转驼峰
SolidWorks GB Library (steel profile library, including aluminum profile, aluminum tube and other structures) installation and use tutorial (generating aluminum profile as an example)
Leetcode T1165: 日志分析
Lvs+kept (DR mode) learning notes