Cấp độ: elementary 25 phútmin Miễn phí Free Junior Builder Junior Builder

JavaScript: Biến và lệnh in JavaScript: Variables and output

Script tính tuổi và hiển thị lời chào A script that calculates age and greets

Bạn sẽ học gì What you will learn

  • Khai báo biến với let và const Declare variables with let and const
  • Gán và thay đổi giá trị biến Assign and change variable values
  • Dùng console.log và alert Use console.log and alert

Bạn sẽ tạo gì What you will build

Script tính tuổi và hiển thị lời chào A script that calculates age and greets

Code mẫu Sample code

javascript
// Tiếng Việt / English: Variables
const ten = "Hà Mi";       // name
const namSinh = 2016;      // birth year
const namNay = 2026;       // current year
let tuoi = namNay - namSinh; // age

console.log(`Xin chào ${ten}! / Hello ${ten}!`);
console.log(`Bạn ${tuoi} tuổi. / You are ${tuoi} years old.`);