7. Quiz Questions

If you would like to look up the answers to the following quiz questions, you can check our discussion forum. If you don't find an answer in the forum, you may create a post asking for an answer to a particular question.

7.1. Question 1: Invocation of constructor

Consider the following class definition:

class Book {
  constructor ({isbn, title, languages}) {
    this.isbn = isbn;
    this.title = title;
    this.languages= languages;
  }
  ...
}

Which of the following expressions represent a correct invocation of the Book constructor? Select one or many:

  1. let b = new Book("006251587X", "Weaving the Web", [1,3]);
  2. let b = new Book({"006251587X", "Weaving the Web", 
                      [LanguageEL.DE,LanguageEL.FR]});
  3. let b = new Book({isbn:"006251587X", title:"Weaving the Web", 
                      languages:[1,3]});
  4. let b = new Book({
        isbn: "006251587X",
        title: "Weaving the Web",
        languages: [LanguageEL.DE, LanguageEL.FR]
    });

7.2. Question 2: Implicit getters and setters

Which of the following code fragments represent correct definitions of a class with implicit getters/setters such that in the constructor, implicit setters are invoked? Select one or many:

  1. class Book {
      constructor (i) {setIsbn(i);}
      get isbn() {return this._isbn;}
      set isbn(i) {this._isbn = i;}
    }
  2. class Book {
      constructor (i) {this.isbn = i;}
      get isbn() {return this._isbn;}
      set isbn(i) {this._isbn = i;}
    }
  3. class Book {
      constructor (i) {this.isbn = i;}
      get isbn() {return this.isbn;}
      set isbn(i) {this.isbn = i;}
    }
  4. class Book {
      constructor (i) {this._isbn = i;}
      get isbn() {return this._isbn;}
      set isbn(i) {this._isbn = i;}
    }

7.3. Question 3: Retrieving the options selected by the user

Consider the following HTML select element:

<select name="languages" multiple="multiple"> 
 <option value="en">English</option>
 <option value="fr">French</option>
 <option value="de">German</option>
</select>

Which of the following expressions represent a correct invocation of the Book constructor? Select one:

  1. O

    document.getElementsByName("languages")[0].options
  2. O

    document.getElementsByName("languages")[0].value
  3. O

    document.getElementsByName("languages")[0].selectedOptions