So basically i have this code which has a return in a function which should then display the returned variable "Price" but the alert box does not show. If i delete all code except alert it will. I can't find any misspelled words or pieces of code. Could you help me ?
<html>
<body>
<script>
var auto = {
merk: 'BMW',
model: 1,
aantal deuren: 5,
bouwjaar: 1990,
prijs : 20000,
price: function(){
return this.prijs;
}
};
var x = auto.price();
alert(x);
</script>
</body>
You have invalid property name in the object:
If the property name is not valid identifier you need to wrap it in quotes: