I am learning javascript from Duckett's book and have noticed that the examples from the book were not working when I copied them onto my text edit. The code is on the website so, I downloaded the files and tried opening them but the same issues showed up on both Chrome and Safari. Here is an example.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript & jQuery - Chapter 3: Functions, Methods & Objects -
Object Constructor</title>
<link rel="stylesheet" href="css/c03.css"/>
</head>
<body>
<h1>TravelWorthy</h1>
<div id="info">
<h2>hotel availability</h2>
<div id="hotelName"></div>
<div id="availability">
<p id="rooms"></p>
<p>rooms left</p>
</div>
<script src="js/multiple-objects.js"></script>
</body>
</html>
// Set up the object
var hotel = new Object();
hotel.name = 'Park';
hotel.rooms = 120;
hotel.booked = 77;
hotel.checkAvailability = function() {
return this.rooms - this.booked;
};
var elName = document.getElementById('hotelName'); // Get element
elName.textContent = hotel.name; // Update HTML with property of the
object
var elRooms = document.getElementById('rooms'); // Get element
elRooms.textContent = hotel.checkAvailability(); // Update HTML with result of method
I've turned off smart quotes and Javascript is enabled. This example is supposed to return the availability of the rooms, but where the numbers should show up, it's blank. This is the third example similar to this that doesn't work.