Init objects sample

This commit is contained in:
2023-08-08 16:44:35 +07:00
parent 9894a57b1a
commit 0646e39cab
2 changed files with 40 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Javascript Training</title>
</head>
<body>
<h1>Javascript Training</h1>
<script src="./index.js"></script>
</body>
</html>
+28
View File
@@ -0,0 +1,28 @@
const info = {
fullName: "Nezumi",
job: "student",
friends: ["Khue", "Huy", "Dat"],
age: (year) => {
return 2023 - year;
},
};
console.log(info);
console.log(info.fullName);
console.log(info["job"]);
const nameKey = "Name";
console.log(info["full" + nameKey]);
const year = prompt("Input your year of birth?");
if (year < 2023) {
alert(`Your age is: ${info.age(year)}`);
} else {
console.log("Invalid age! Please try again!");
}
info.location = "VietNam";
info["facebook"] = "Nezumi2711";
console.log(info);