export class Car {
public brand: string = "";
public model: string = "";
start(): void{
console.log(`${this.brand} ${this.model} is starting...`);
}
accelerate(): void{
console.log(`${this.brand} ${this.model} is accelerating...`);
}
brake(): void{
console.log(`${this.brand} ${this.model} is braking...`);
}
stop(): void{
console.log(`${this.brand} ${this.model} is stopping...`);
}
}
import { Car } from "./car";
const car = new Car();
car.brand = "Toyota";
car.model = "Camry";
car.start();
// Toyota Camry is starting...
car.accelerate();
// Toyota Camry is accelerating...
car.brake();
// Toyota Camry is braking...
car.stop();
// Toyota Camry is stopping...
# TypeScript Quiz — ข้อ 1 (1 คะแนน)
## 🎯 คำสั่ง
ให้นักเรียนสร้าง class Car ในไฟล์ car.ts
โดยต้องทำให้ไฟล์ index.ts ที่กำหนดให้ สามารถทำงานได้ถูกต้อง และได้ผลลัพธ์ตามที่คาดหวัง
ห้ามแก้ไขไฟล์ index.ts
## 📌 หมายเหตุสำคัญ
**ในไฟล์ `index.ts` มี comment (`//`) ที่แสดงตัวอย่างผลลัพธ์ที่คาดหวัง**
ให้นักเรียนอ่านผลลัพธ์จาก comment เหล่านั้น แล้วเขียน method logic ใน class ต่างๆ ให้สอดคล้องกับผลลัพธ์ที่แสดงไว้
**ตัวอย่าง:**
```typescript
car.start();
// Toyota Camry is starting...
จาก comment ด้านบน แสดงว่าผลลัพธ์ที่คาดหวังคือ "Toyota Camry is starting..." ดังนั้น method start() ใน class Car ต้องแสดงผลลัพธ์ในรูปแบบนี้
📁 โครงสร้างไฟล์ที่ต้องมี
p01/
├── car.ts ← นักเรียนต้องสร้าง
└── index.ts ← ไฟล์ที่กำหนดให้
brand และ modelstart() สำหรับแสดงข้อความเริ่มทำงานany