mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 20:01:31 +00:00
Init objects sample
This commit is contained in:
@@ -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>
|
||||||
@@ -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);
|
||||||
Reference in New Issue
Block a user