commit 6439615a3f2b630065f427bc3ce03e7c44fa4a4c Author: Your Name Date: Fri May 15 20:35:45 2026 +0700 up diff --git a/bai_tap_dem_so.js b/bai_tap_dem_so.js new file mode 100644 index 0000000..aad6172 --- /dev/null +++ b/bai_tap_dem_so.js @@ -0,0 +1,36 @@ +// Bài 1: Viết chương trình khởi tạo nhập vào một mảng số nguyên gồm 10 phần tử. +// Chương trình thực hiện tính và hiển thị xem có bao nhiêu số nguyên lớn hơn hoặc bằng 10. + +let count = 10; +let soNguyenList = [] + +// 1 2 3 4 5 6 7 8 9 10 => 1 +// 1 20 3 4 50 6 7 8 9 10 => 3 +let demKq = 0; + +for(let i = 0; i < count; i++) { + let soNguoiDungNhap = +prompt("Nhập số nguyên thứ " + (i + 1)); + + while(true) { + if (isNaN(soNguoiDungNhap)) { + alert("phải nhập số") + soNguoiDungNhap = +prompt("Nhập số nguyên thứ " + (i + 1)); + }else { + break; + } + } + + soNguyenList[i] = soNguoiDungNhap; + if(soNguyenList[i] >= 10) { + demKq = demKq + 1; + } +} + +console.log("soNguyenList", soNguyenList) + +console.log("số nguyên lớn hơn or bằng 10 trong danh sách là ", demKq) + + +// do { + +// }while(true); \ No newline at end of file diff --git a/de_luyentap.md b/de_luyentap.md new file mode 100644 index 0000000..0a39f22 --- /dev/null +++ b/de_luyentap.md @@ -0,0 +1 @@ +https://docs.google.com/document/d/1ZjZ2I1whYLjWcz3kbqVJdk4FKrQVnpnYnYsLuwOiddg/edit?usp=sharing \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..6d5e53e --- /dev/null +++ b/index.html @@ -0,0 +1,15 @@ + + + + + + Document + + +

+ + + + \ No newline at end of file diff --git a/js_array_learning.js b/js_array_learning.js new file mode 100644 index 0000000..e633658 --- /dev/null +++ b/js_array_learning.js @@ -0,0 +1,37 @@ +let studentNameList = [ + "Phước", + "Vũ Anh", + "Ánh Dương" +] + + +for(let i = 0; i < studentNameList.length; i++) { + console.log(studentNameList[i]) +} + +for (let studentName of studentNameList) { + console.log(studentName) +} + +for (let key in studentNameList) { + console.log(key) +} + +// i -> index +// studentNameList[i] -> value +// studentNameList.length -> thuộc tính length + +// studentNameList.push() -> phương thức (method ~ function) + +// studentNameList.push("Nam") +// studentNameList.push("Hồng", "Yến", "Tâm") + +console.log("studentNameList", studentNameList) + +studentNameList.splice(1, 1) + +console.log("studentNameList", studentNameList) + +studentNameList[0] = "Phước Đẹp Trai" + +console.log("studentNameList", studentNameList) \ No newline at end of file diff --git a/js_object_learning.js b/js_object_learning.js new file mode 100644 index 0000000..679aca5 --- /dev/null +++ b/js_object_learning.js @@ -0,0 +1,44 @@ +// let myName = "Phước" +// let myAge = 30 +// let myNumberPhone = "0329577177" +// let isCoNguoiYeu = false +// let friendNameList = [ +// "Toàn", +// "Trí", +// "Trung" +// ] + +// let nameList = ["Phước", "Toàn"] +// let ageList = [30, 27] + +// let friendList = [[ +// "Toàn", +// "Trí", +// "Trung" +// ], []] + + +let person = { + name: "Phước", + age: 30, + numberPhone: "0329577177", + isCoNguoiYeu: false, + friendNameList: [ + "Toàn", + "Trí", + "Trung" + ], + address: { + provinceID: 1, + wardId: 1, + des: "Xã ./asd/asd" + } +} + +person.isGiau = false + +delete person["isCoNguoiYeu"] + +person.isCoNguoiYeu = true + +console.log("personList", person) diff --git a/main.js b/main.js new file mode 100644 index 0000000..e69de29 diff --git a/quan_ly_sach.js b/quan_ly_sach.js new file mode 100644 index 0000000..a077c8c --- /dev/null +++ b/quan_ly_sach.js @@ -0,0 +1,101 @@ +/* + +Luyện tập thao tác với mảng đối tượng trong JavaScript, bao gồm: + +Thêm mới sách vào danh sách. +Hiển thị danh sách sách. +Tìm kiếm sách theo tên. +Xóa sách theo ID. +Thoát chương trình. + + +book -> id, title, author, category, price + +*/ + + + +const bookList = [ + { + id: -1, + title: "Học cách yêu", + author: "Nguyễn Phước", + category: "tình cảm", + price: 99999 + }, + { + id: -2, + title: "Học làm giàu", + author: "Nguyễn Phước", + category: "đời sống", + price: 10000 + } +] + +let genId = 0; +let choice = null; +do { + console.log("1/ Thêm Sách") + console.log("2/ Hiển thị Sách") + console.log("3/ Tìm sách (by title)") + console.log("0/ Thoát") + choice = +prompt("Nhập lựa chọn của bạn") + + switch (choice) { + case 1: + let id = genId++; + + let newBook = { + id, + title: prompt("Nhập tên sách!", "Sách " + id), + author: prompt("Nhập tên tác giả"), + category: prompt("Nhập danh mục sách"), + price: +prompt("Nhập giá sách", 0) + } + + /* Check giá */ + while (isNaN(newBook.price)) { + newBook.price = +prompt("Nhập giá sách", 0); + } + + bookList.push(newBook); + + alert("Thêm thành công!") + + break; + case 2: + if (bookList.length == 0) { + console.log("Không có sách nào trong kho!") + break; + } + console.log("bookList", bookList) + break + case 3: + let inputSearch = prompt("Nhập từ khóa muốn tìm") + console.log("Sách tìm thấy: ") + for (book of bookList) { + // "Học cách yêu".includes("yêu") => true + // "Học cách yêu".includes("giàu") => false + if (book.title.replaceAll(" ", "").toLowerCase().includes(inputSearch.replaceAll(" ", "").toLowerCase())) { + console.log("book", book.title) + } + } + break; + case 4: + let inputId = prompt("Nhập id muốn xóa!") + for(let i = 0; i < bookList.length; i++) { + if(bookList[i].id == inputId) { + bookList.splice(i, 1) + break; + } + } + console.log("danh sách sau xóa là", bookList) + break; + case 0: + break; + default: + alert("Lựa chọn không hợp lệ!") + } + + +} while (choice != 0) \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..5905c2e --- /dev/null +++ b/test.js @@ -0,0 +1 @@ +console.log("asdas asd fd asds ".replaceAll(" ", "")) \ No newline at end of file