当前位置:网站首页>附录2-一些简单的练习
附录2-一些简单的练习
2022-07-29 09:17:00 【Suyuoa】
目录
4.1 将数组中的所有元素和到一个字符串中并且每一个元素用星号隔开
1 alert与prompt
1.1 年龄计算

这里这个日期应该可以不写死,后面可以使用date对象


1.2 简单计算器
JS中也是有eval的





2 判断类
2.1 年龄判断
输入年龄后判断是否大于18岁

2.2 闰年判断
闰年有两种达成方式,能被4整除且不能整除100 或 能够被400整除

2.3 成绩判断
我们判断
- 90以上是A
- 80到90(不含)是B
- 70到80(不含)是C
- 60到70(不含)是D
- 以上条件都未达成不给评价

这里我们利用了执行顺序(如果第一个条件达成就不会再往下进行判断),从大向小写,这样我们不需要再添加成绩的上限
- 不过这样会导致代码的语义变差,所以实际工作中最好是把上限与下限都写上
2.4 数字补0
如果输入的数小于10,比如说1,就alert一个01,如果大于等于10就alert原值



3 循环类
以1-100的整数作为操作对象
3.1 所有数加和
for方法

![]()
while方法

![]()
3.2 所有数平均

![]()
3.3 奇数和与偶数和


这里我们不知道结果对不对,我们这里将最大值改成3

发现结果是对的
![]()
3.4 所有能被3整除的和

![]()
这里有另一种写法

![]()
3.5 跳过个位数为3的所有整数和

![]()
这里如果最后的数不是100,那么if中的除数也要有所变化,比如当要加倒1000的时候,那么除数就要变为100
3.6 求平均数
用户先说几个数,几个数就输入几次,最后出结果

经测试符合要求
3.7 追加多个相同字符串

![]()
3.8 打印三角形
- 如果想都放在一块,就在i中为内容加换行符,循环结束后打印一次。而不是每一轮i都打印一次
3.8.1 正的


3.8.2 倒的


3.9 打印九九乘法表


3.10 打印6行7列相同的内容

![]()
3.11 无限次猜数字

如果使用do while就可以这样写

3.12 简易ATM


4 数组类
4.1 将数组中的所有元素和到一个字符串中并且每一个元素用星号隔开

![]()
这个可以用join()来搞

![]()
如果你想要最后一个星号,直接加上就行了
4.2 一个数组里面放1到10的整数

![]()
4.3 翻转数组

![]()
可以使用reverse

![]()
5 函数类
5.1 封装反转数组

5.2 封装冒泡排序

![]()
5.3 封装判断闰年



5.4 嵌套封装判断闰年


![]()
6 猜1-10之间的随机整数

经测试可以实现功能
7 倒计时

注意的点就是取秒数这种信息是取余数做的
打开网页后是这样的

我们点击一下按钮

再点击一下按钮

从打开网页的时候就开始计时,点击按钮后可以查看还剩下多长时间
如果你想直接给一个日子,那么可以这样写


8 处理字符串
我们处理字符串 abaasdffggghhjjkkgfdsssss3444343 找到下面几种结果
8.1 字符串长度
![]()
![]()
8.2 找出索引 0,3,5,9 的字符

![]()
8.3 查找i,c,b三种字符是否在字符串中


8.4 将g替换为22,ss替换为b

![]()
8.5 截取索引1-5的字符串(包含索引5)

![]()
8.6 找出字符串中出现最多的字符与出现的次数

![]()
9 开关灯案例



10 换肤效果

打开后有两张图片

点谁就会让谁铺满背景


由于用了循环,所以多放几张也可以
11 多个下拉菜单
一般我们都用ul和li来写
CSS

html

JS

移动到第几个消息下面的下拉菜单就会显示出来

边栏推荐
- Excellent Allegro skill recommendation
- Collation of ml.net related resources
- C# 使用RestSharp库实现POST请求
- Floweable advanced
- A structured random inactivation UNET for retinal vascular segmentation
- 浅谈契约测试
- Could not receive a message from the daemon
- What is the difference between the pre training model and the traditional method in sorting?
- [performance optimization methodology series] III. core idea of performance optimization (2)
- 解决Base64 报错 Illegal base64 character
猜你喜欢

Outlook tutorial, how to create an electronic signature in outlook?

VS2015采用loadlibrary方式调用dll库

【Unity入门计划】C#与Unity-了解类和对象
![[machine learning] naive Bayesian code practice](/img/42/38e8cfa8ebfbb0e14c2e26ffc6c793.png)
[machine learning] naive Bayesian code practice

优秀的Allegro Skill推荐

redis可视化工具读取数据乱码问题解决

Leetcode: interview question 08.14. Boolean operation
![[machine learning] logistic regression code exercise](/img/dc/203f240e2eb213dbd6173d17e47ec6.jpg)
[machine learning] logistic regression code exercise
![Acwing game 59 [End]](/img/a6/70d76e78e49dc2ad08084f58750017.png)
Acwing game 59 [End]

How does alternates achieve high-performance publish and subscribe?
随机推荐
Design of distributed (cluster) file system
Could not receive a message from the daemon
2022 P cylinder filling test simulation 100 questions simulation test platform operation
One click automated data analysis! Come and have a look at these treasure tool libraries
(Video + graphics) introduction to machine learning series - Chapter 1 Introduction
存算一体与存内计算计算杂谈
ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
简述堆和栈的区别
Leetcode question brushing (6)
What is the key to fast multi tag user profile analysis?
【Unity入门计划】常用学习网址收藏
Want to know how to open an account through online stock? Excuse me, is it safe to open a stock account by mobile phone?
What is the difference between the pre training model and the traditional method in sorting?
乱打日志的男孩运气怎么样我不知道,加班肯定很多
C # use database to bind listview control data
Leetcode question brushing (6)
Memory leaks and common solutions
md
基于ArkUI eTS开发的坚果新闻(NutNews)
Multiple knapsack, simplicity and binary optimization