JavaScript 第二章总结

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.





posted @   FBshark  阅读(254)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示