1 · The words 2 · The machines 3 · Build something

🟨 JavaScript Lab

Every web page you open is made of three things. HTML is the words and the pictures. CSS is the colours. JavaScript is the part that moves. When you click a button and something happens, that is JavaScript. 你打开的每一个网页都由三样东西组成。HTML 是文字和图片。CSS 是颜色。 JavaScript 是会的那一部分。你点一个按钮,然后有事情发生——那就是 JavaScript。 ทุกหน้าเว็บที่คุณเปิดทำจากสามอย่าง HTML คือคำและรูปภาพ CSS คือสี JavaScript คือส่วนที่ขยับได้ เมื่อคุณคลิกปุ่มแล้วมีอะไรเกิดขึ้น นั่นคือ JavaScript

You need nothing to start. No money. No new computer. Your browser can already run JavaScript. Work in this order: learn the words, drive the machines, then build a game and a map. 开始不需要任何东西。不用花钱,不用换电脑。你的浏览器已经能运行 JavaScript 了。 按这个顺序学:先学词,再驾驶机器,然后做一个游戏和一张地图。 เริ่มต้นไม่ต้องใช้อะไรเลย ไม่ต้องใช้เงิน ไม่ต้องซื้อคอมใหม่ เบราว์เซอร์ของคุณรัน JavaScript ได้อยู่แล้ว เรียนตามลำดับนี้: เรียนคำศัพท์ ขับเครื่องมือ แล้วสร้างเกมกับแผนที่

👾 Tutorial 1 — make a space game. Nine steps. You start with an empty file and finish with a game you can play with the arrow keys.
教程一 —— 做一个太空游戏。九步。从一个空文件开始,最后做出可以用方向键玩的游戏。

บทเรียนที่ 1 — สร้างเกมอวกาศ เก้าขั้นตอน เริ่มจากไฟล์เปล่า จบด้วยเกมที่เล่นได้ด้วยปุ่มลูกศร
Open ▸
🗺️ Tutorial 2 — make a map of Chiang Mai. Real places, real numbers. Zoom in and out, and draw squares, circles and lines on top.
教程二 —— 做一张清迈地图。真实地点,真实数字。可以放大缩小,还能在上面画方形、圆形和线。

บทเรียนที่ 2 — สร้างแผนที่เชียงใหม่ สถานที่จริง ตัวเลขจริง ซูมเข้าออกได้ และวาดสี่เหลี่ยม วงกลม เส้น ทับลงไปได้
Open ▸

🔤 The words you need

Summary

Twenty-two words. Every word here is a real word from real code. Programmers all over the world say these words in English, so learning them is learning the job. Tap say it to hear one. Tap tell me more for the long answer.

摘要

二十二个词。这里每个词都来自真实代码。全世界的程序员都用英语说这些词,所以学会它们就是学会这份工作。点“say it”听发音,点“tell me more”看详细解释。

สรุป

ยี่สิบสองคำ ทุกคำมาจากโค้ดจริง โปรแกรมเมอร์ทั่วโลกพูดคำเหล่านี้เป็นภาษาอังกฤษ เรียนคำพวกนี้คือเรียนงานจริง แตะ say it เพื่อฟัง แตะ tell me more เพื่ออ่านคำอธิบายยาว

🔧 Nine little machines

Each machine shows real JavaScript on the left and the real result on the right. Move the slider, type a word, press a button. The code you see is the code that runs. 每台机器左边是真正的 JavaScript,右边是真正的运行结果。拖滑块、打字、按按钮。 你看到的代码就是正在运行的代码。 แต่ละเครื่องแสดงโค้ด JavaScript จริงทางซ้าย และผลลัพธ์จริงทางขวา เลื่อนแถบ พิมพ์คำ กดปุ่ม โค้ดที่คุณเห็นคือโค้ดที่กำลังทำงานอยู่

📦 1 · A variable is a box with a name

Summary

A variable is a box with a name. You put a value inside. Later you use the name, and the computer gets the value. The word let makes a new box. The equals sign puts something in it. Move the slider to change what is in the box.

摘要

变量就是一个有名字的盒子。你把一个值放进去。之后你用名字,电脑就取出那个值。let 造一个新盒子,等号把东西放进去。拖动滑块看盒子里的东西改变。

สรุป

ตัวแปรคือกล่องที่มีชื่อ คุณใส่ค่าไว้ข้างใน ทีหลังคุณเรียกชื่อ คอมพิวเตอร์ก็หยิบค่านั้นมาให้ คำว่า let สร้างกล่องใหม่ เครื่องหมายเท่ากับใส่ของลงไป เลื่อนแถบเพื่อเปลี่ยนของในกล่อง

let score = 3; score = score + 10; console.log(score); // 13
Why let? let means "make a new box". You only write it the first time. After that you just use the name. 为什么用 let?let 的意思是“造一个新盒子”。只在第一次写它,之后直接用名字。 ทำไมต้อง let? let แปลว่า "สร้างกล่องใหม่" เขียนแค่ครั้งแรก หลังจากนั้นใช้แค่ชื่อ
score is 3

🚀 Now build something real

Summary

You now know nine ideas. That is enough to build real things. The space game uses all nine. The map uses seven of them, and adds real numbers from real places in Chiang Mai. Open one and follow the steps.

摘要

你已经学会九个概念,这足够做真东西了。太空游戏九个全用上;地图用了其中七个,还加上清迈真实地点的真实数字。打开一个,按步骤做。

สรุป

ตอนนี้คุณรู้เก้าแนวคิดแล้ว พอสำหรับสร้างของจริง เกมอวกาศใช้ครบทั้งเก้า แผนที่ใช้เจ็ดอย่าง แล้วเพิ่มตัวเลขจริงจากสถานที่จริงในเชียงใหม่ เปิดอันไหนก็ได้แล้วทำตามขั้นตอน

👾 Make a space game. Empty file → HTML page → canvas → a ship you drive → bullets → aliens → score. Nine steps with copy buttons.
做一个太空游戏:空文件 → HTML 页面 → 画布 → 你能开的飞船 → 子弹 → 外星人 → 分数。九步,每步都能复制代码。

สร้างเกมอวกาศ: ไฟล์เปล่า → หน้า HTML → แคนวาส → ยานที่คุณบังคับ → กระสุน → เอเลี่ยน → คะแนน เก้าขั้นตอน คัดลอกโค้ดได้
Start ▸
🗺️ Make a map with drawing tools. Real Chiang Mai coordinates, zoom in and out, and tools to draw squares, circles and lines on top.
做一张带绘图工具的地图:真实的清迈坐标,可放大缩小,还有画方形、圆形和线的工具。

สร้างแผนที่พร้อมเครื่องมือวาด: พิกัดเชียงใหม่จริง ซูมเข้าออก และเครื่องมือวาดสี่เหลี่ยม วงกลม เส้น
Start ▸

Want the same two projects in Python? They are here: the Python space game and the Python map. Same ideas, different language — a very good way to see what is really a programming idea and what is only a word. 想用 Python 做同样两个项目?在这里:Python 太空游戏Python 地图。同样的思路,不同的语言——这是看清什么才是真正的编程概念、 什么只是写法的好办法。 อยากทำสองโปรเจกต์เดียวกันด้วย Python ไหม อยู่ที่นี่: เกมอวกาศ Python และ แผนที่ Python แนวคิดเดียวกัน คนละภาษา เป็นวิธีที่ดีมากในการเห็นว่าอะไรคือแนวคิดการเขียนโปรแกรมจริง ๆ และอะไรเป็นแค่คำ

📌 Points to remember

  • A variable is a box with a name. let makes it. = puts something in. 变量是有名字的盒子:let 造盒子,= 放东西进去。 ตัวแปรคือกล่องที่มีชื่อ let สร้าง = ใส่ของ
  • Quotes make words. 5 is a number. "5" is a string. 引号造出文字:5 是数字,"5" 是字符串。 เครื่องหมายคำพูดทำให้เป็นคำ 5 คือตัวเลข "5" คือสตริง
  • Count from zero. The first item in a list is item zero. 从零开始数:列表里第一个是第 0 个。 นับจากศูนย์ ตัวแรกในลิสต์คือตัวที่ศูนย์
  • A function is a machine with a name. Write the job once, use the name for ever. 函数是有名字的机器:活儿写一次,名字用一辈子。 ฟังก์ชันคือเครื่องที่มีชื่อ เขียนงานครั้งเดียว ใช้ชื่อไปตลอด
  • Events wake your code up. Nothing runs until something happens. 事件唤醒你的代码:什么都不发生,代码就不跑。 อีเวนต์ปลุกโค้ดของคุณ ไม่มีอะไรทำงานจนกว่าจะมีอะไรเกิดขึ้น
  • Animation is wipe, move, draw, again. Sixty times a second. 动画就是:擦、移、画、再来——每秒六十次。 แอนิเมชันคือ ลบ ขยับ วาด ทำใหม่ หกสิบครั้งต่อวินาที
  • Every browser has the tools already. Press F12 to open the console and see your own console.log messages. 浏览器里已经有全部工具:按 F12 打开控制台,看自己的 console.log เบราว์เซอร์มีเครื่องมือครบอยู่แล้ว กด F12 เปิดคอนโซลเพื่อดูข้อความ console.log ของคุณเอง

Thank you for learning with us today. Go and break something, then fix it. See you in the next lab. 感谢今天和我们一起学习。去弄坏点东西,然后把它修好。下个实验室见。 ขอบคุณที่เรียนกับเราวันนี้ ไปทำอะไรพังแล้วซ่อมมันซะ แล้วเจอกันในแล็บหน้า