JavaScript 第二章总结

本文详细介绍了程序设计的基本步骤,包括高级设计、流程图制作及伪代码的运用。重点讲解了变量和逻辑在伪代码中的作用,以及如何使用JavaScript内置函数如alert、prompt和Math.random进行实际编程。同时,还探讨了布尔运算符和数学函数的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Writing real code

设计程序的步骤

  1. First, a high-level design and a flowchart
  2. more details
  3. Working through the Psedocode:作者将 psedocode 分为了两个部分,分别是 variables 和 logic ,它们的作用分别是

The variables will tell us what we need to keep track of in our code, and the logic describes what the code has to faithfully implement to create the game.(And using indentation to help make the psedocode easier to read.)

认识 boolean operators

boolean opetators 有两种:comparison operators 和 logical operators.

  • Comparison Operators compare two values
  • Logical Operatore combine two boolean expessions to create one boolean result

一些 JavaScript 的 bultin-functions

alert("content")

用于显示一个含有 content 的 dialogue box.

prompt("prompt")

作用:和 alert 特别像,另外还有一个可供 User 输入的输入框,User 在里面的输入值称为这个函数的返回值。这个输入值的类型是 string 类型的。
注意:在这里和 C 语言有一点不同的是:当你输入一个数字的时候,返回的时候是一个字符,但是如果写成和另外一个数字比较的形式,JavaScript 会自动将这个字符串转换为数字。

Math.random()

Mathrandom()没有参数,返回一个0~1的数(including 0, but not including 1),如果想要一个0~(n-1).9999的数,可以这样写:var randomLoc = Math.random()*n

Math.floor(num)

Math.floor()用于将 num round down to their nearest interger value.





转载于:https://www.cnblogs.com/FBsharl/p/10149832.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值