Get Programming with JavaScript - Listing 3.01
Listing 3.01 - Using variables to represent a book
JS Bin
var bookTitle;
var bookAuthor;
bookTitle = "The Hobbit";
bookAuthor = "J. R. R. Tolkien";
console.log(bookTitle + " by " + bookAuthor);
Further Adventures
Listing 3.01 - Using variables to represent a book - Tasks 1 and 2
- Declare variables for a second book and assign them values.
- Add code to log its details to the console.
var bookTitle;
var bookAuthor;
var book2Title; // declare variables
var book2Author; //
bookTitle = "The Hobbit";
bookAuthor = "J. R. R. Tolkien";
book2Title = "Northern Lights"; // assign them values
book2Author = "Philip Pullman"; //
console.log(bookTitle + " by " + bookAuthor);
console.log(book2Title + " by " + book2Author); // log details
Listing 3.01 - Using variables to represent a book - Task 3
- Repeat tasks 1 and 2 for a third book.
var bookTitle;
var bookAuthor;
var book2Title;
var book2Author;
var book3Title;
var book3Author;
bookTitle = "The Hobbit";
bookAuthor = "J. R. R. Tolkien";
book2Title = "Northern Lights";
book2Author = "Philip Pullman";
book3Title = "The Adventures of Tom Sawyer";
book3Author = "Mark Twain";
console.log(bookTitle + " by " + bookAuthor);
console.log(book2Title + " by " + book2Author);
console.log(book3Title + " by " + book3Author);