added new exercice
This commit is contained in:
1 parent
fe12673e77
commit
ac12d7722c
2 files changed
+44
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>title</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="livre"></div>
|
||||||
|
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
console.log("hello world")
|
||||||
|
|
||||||
|
|
||||||
|
// question 1.b
|
||||||
|
|
||||||
|
let livre = {
|
||||||
|
nom: "JS the good part",
|
||||||
|
year: 2008,
|
||||||
|
price: 19.75,
|
||||||
|
publisher: "O reilly"
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(livre);
|
||||||
|
|
||||||
|
function getAttribute(object, key, defaultValue){
|
||||||
|
if(Object.hasOwn(object, key)){
|
||||||
|
return object[key];
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = "age"
|
||||||
|
let object = {age: 100};
|
||||||
|
let defaultValue = 0;
|
||||||
|
console.log("2.a >> " + getAttribute(object, key, defaultValue)) // 100
|
||||||
|
console.log("2.a >> " + getAttribute({name: "claudette"}, "name", 0)) // claudette
|
||||||
|
|
||||||
|
console.log("2.a >> " + getAttribute({age: 100}, "name", "no name")) // no name
|
||||||
|
console.log("2.a >> " + getAttribute({name: "claudette"}, "age", 0)) // 0
|
||||||
Reference in new issue
Block a user