This commit is contained in:
rou
2026-03-23 16:33:09 +08:00
parent 8b83f63235
commit d5ff59ac76
7 changed files with 31 additions and 4 deletions

View File

@@ -1,7 +1,10 @@
let age: number = 18;
let age: number = 88;
let userName: string = "Tom";
let isPaid: boolean = true;
// 任务:
// 1. 修改上面的值,让它们更像一个学习者资料
// 2. 输出一句完整信息
console.log(`姓名:${userName}
年龄:${age}
状态:${isPaid}`);

View File

@@ -2,9 +2,12 @@ const scoreList: number[] = [82, 90, 95];
function sum(a: number, b: number): number {
// 返回两个数字之和
return 0;
return a + b;
}
console.log(scoreList, sum(2, 3));
// 任务:
// 1. 改写 sum 的返回值
// 2. 调用 sum

View File

@@ -13,3 +13,4 @@ const user: User = {
// 任务:
// 1. 把对象内容改成学习者资料
// 2. 输出 name 和 age
console.log(user.name, user.age);

View File

@@ -2,6 +2,9 @@ function getData<T>(data: T): T {
// 返回 data
return data;
}
const n = getData<number>(100)
const s = getData("123")
console.log(n, s);
// 任务:
// 1. 用 number 调用

View File

@@ -4,6 +4,15 @@ interface User {
name: string;
age?: number;
}
id = "hello"
const userA: User = {
name: "小李",
age: 18
}
const userB: User = {
name: "小柔"
}
console.log(userA, userB);
// 任务:
// 1. 把 id 改成字符串也试一次

View File

@@ -11,8 +11,12 @@ const courses: Course[] = [
function renderCourseLines(list: Course[]): string[] {
// 返回渲染后的字符串数组
return [];
const a = list.map(item => {
return item.title
})
return a;
}
console.log(renderCourseLines(courses));
// 任务:
// 1. 实现 renderCourseLines

View File

@@ -18,7 +18,9 @@ function pickFirst<T>(list: T[]): T {
function formatStudent(student: Student): string {
// 返回一段摘要文字
return "";
return `学号:${student.id}
姓名:${student.name}
年龄:${student.age?.toFixed()}`;
}
const student: Student = {
@@ -30,6 +32,8 @@ const student: Student = {
],
};
console.log(formatStudent(student), pickFirst(student.courses));
// 任务:
// 1. 实现 formatStudent
// 2. 用 pickFirst 取第一门课程