Javascript coding
Javascript coding
本文关键字:coding Javascript 更新时间:2023-09-26
我正疯狂地试图编写一个JavaScript代码,它向用户请求任何数字序列,直到用户输入"N"。
如果发生这种情况,将弹出一条消息,指示用户已到达该序列的末尾,然后弹出一条新消息,显示用户输入的"所有"数字,并按新月形排列。
有什么建议吗?
我很感激任何帮助,因为我现在想什么都快疯了。
如果指定了数组,那么我就不会有问题,但由于它是一个随机数组,我似乎找不到正确的答案。
您想要做的是这样的事情:
-
获取用户的号码并将其预先保存在数组中。
-
循环浏览所有数字,检查数字是否为N.
-
如果是,请提醒用户。
-
对数组进行排序,提醒用户。
尝试编码:
// All the user's numbers
var UserNumbers = [15, 10, 11, 12, 13];
//The value to search for
var N = 12;
//Loop through the values
for(var i = 0; i < UserNumbers.Length; i++){
if(UserNumbers[i] == N){
//The number matches
alert("You reached the end of the sequence";
}
}
// I am not sure what you mean with cresent order so that you'll have to solve for yourself.
//Sort the UserNumbers here
//Store the message to show the user
var message = "";
//Loop through the values - now in correct order and save them to the message
for(var i = 0; i < UserNumbers.Length; i++){
//Add to the message
message += UserNumbers[i] + " ";
}
//Show the message - all the containing numbers
alert(message);
虽然这是一个有用的社区,但我很确定,我们不是由这里的老师来教你如何编码的。既然这听起来像是家庭作业,而不是现实生活中的场景,那就和你的老师或同学谈谈吧。祝你好运,下次在发布问题之前,试着做一些研究——有很多初学者教程。
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 使用php或javascript从facebook相册URL中删除多余的部分
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在JavaScript中将字符串转换为函数引用
- 模糊事件的Javascript测试
- Javascript更改图标
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何使用WCF服务和javascript表单post上传.doc文件
- javascript结合了数组和字典
- 这是什么 ==- javascript 运算符
- 从javascript创建一个列表
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Javascript:selenium Web驱动程序isDisplayed()不工作
- 如何通过ajax刷新JSF填充的javascript变量
- 如何在Javascript中将JSon对象转换为数组
- Javascript coding
- JavaScript and UTF-8 coding
- Coding Razor and JavaScript