up
This commit is contained in:
36
bai_tap_dem_so.js
Normal file
36
bai_tap_dem_so.js
Normal file
@@ -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);
|
||||||
1
de_luyentap.md
Normal file
1
de_luyentap.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://docs.google.com/document/d/1ZjZ2I1whYLjWcz3kbqVJdk4FKrQVnpnYnYsLuwOiddg/edit?usp=sharing
|
||||||
15
index.html
Normal file
15
index.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1></h1>
|
||||||
|
|
||||||
|
<script src="main.js">
|
||||||
|
/*script js*/
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
37
js_array_learning.js
Normal file
37
js_array_learning.js
Normal file
@@ -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)
|
||||||
44
js_object_learning.js
Normal file
44
js_object_learning.js
Normal file
@@ -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)
|
||||||
101
quan_ly_sach.js
Normal file
101
quan_ly_sach.js
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user