0
objects in JavaScript
i can't make objects with javascript, even tough i copy it all from the sololearn examples, anyone can help???
6 Answers
+ 6
Do you mean Js objects or DOM objects like "<div>","<a>"...?
+ 2
Do you have an example of what is not working correctly that you could provide?
Edit: added in NIR DERI âs example.
js:
var person={
name: "John", age: 31,
favColor: "green", height: 183
};
html:
<html>
<head>
<title>not_working_objects</title>
<script src="java/introducing_objects.js"></script>
</head>
<body>
</body>
</html>
Currently if you were to load this webpage nothing would happen.
To YOU at least.
To the webpage, it just stored an object that has about 4 properties attached to it in the background. It didnât notify you about it because you didnât do anything with it.
You said this doesnât work, however you would have little way of checking if it did work unless you went and typed in person.name into the console or something.
Try adding console.log(person.name);
after the object is made.
+ 2
Your object in SL playground
https://code.sololearn.com/W8N4i5hLvNQf/?ref=app
+ 1
let myObjectCar = {
model: 'Audi',
color: 'white',
price: '5000#x27;
}
console.log(myObjectCar.price)
+ 1
Your object in html:
https://code.sololearn.com/WjLE90m621ef/?ref=app
0
js:
var person={
name: "John", age: 31,
favColor: "green", height: 183
};
html:
<html>
<head>
<title>not_working_objects</title>
<script src="java/introducing_objects.js"></script>
</head>
<body>
</body>
</html>