Coursera Answers

JavaScript jQuery and JSON Week 3 Practice Quiz Answer

JavaScript jQuery and JSON Week 3 Practice Quiz Answer


 

JavaScript jQuery and JSON 

Week 3 Practice Quiz Answer



JQuery



Question 1)

What is the purpose of the following JQuery ready() call?


  1. $(document).ready(function(){
  2.  window.console && console.log(‘Hello JQuery..’);
  3. });


  • Ascertain if the document is ready to load
  • Clear the browser window so drawing can start in the upper left hand corner
  • Register a function that will be called when the HTML document is completely loaded
  • Enable the retrieval of data in the JSON format




Question 2)

What portion of the DOM (Document Object Model) will be affected by the following JQuery statement:


$(‘#para’).css(‘background-color’, ‘red’);


  • All tags with a class attribute of “para”
  • A tag with an id attribute of “para”
  • All  elements in the DOM
  • A tag with a class attribute of “para”




Question 3)

What does the following JQuery code do?


$(‘#spinner’).toggle();


  • Call the global JavaScript function toggle with the spinner tag as its parameter
  • Switch the spinner.gif with the image spinner_toggle.gif
  • Hide or show the contents of a tag with the id attribute of “spinner”
  • Indicate that page loading has completed




Question 4)

What will the following JQuery code select from the given HTML?


  1. <p id=”p”>two
  2.   <input type=”text” name=”one” value=”three” title=”four”>
  3.   <input type=”text” name=”five” class=”p” value=”p”>
  4. </p>
  5. <script>
  6. $(‘#p’).find(‘input[name=”one”]’).val();
  7. </script>


  • three
  • five
  • one
  • two
  • four




Question 5)

Which of the following is not a primitive type supported in JSON?


  • integer
  • boolean
  • url
  • string
  • array




Question 6)

In the following JSON, how would you print the value “six”?


  1. data = {‘one’:’two’, ‘three’: 4,
  2.   ‘five’ : [ ‘six’, ‘seven’ ],
  3.   ‘eight’ : { ‘nine’ : 10, ‘ten’ : 11  }
  4. }


  • alert(data.five[0])
  • alert(five.six)
  • alert(data.eight.nine)
  • alert(five)
  • alert(data[‘six’])




Question 7)

What would the following JavaScript print out?


  1. data = {‘one’:’two’, ‘three’: 4,
  2.   ‘five’ : [ ‘six’, ‘seven’ ],
  3.   ‘eight’ : { ‘nine’ : 10, ‘ten’ : 11  }
  4. };
  5. alert(data.eight.nine);



  • 10
  • 11
  • nine
  • seven
  • six




Question 8)

In the following code, what would you expect in the variable named “data”?


  1. $.getJSON(‘json.php’, function(data) {
  2.     $(“#back”).html(data.first);
  3.     window.console && console.log(data);
  4.  });

  • The tag in the DOM that has an id attribute of “first”
  • A string that is the entire HTTP response of the output from the script json.php
  • Either a JavaScript object or list depending on the returned output of the script json.php
  • All of the tags from the DOM with a class attribute of “back”




Question 9)

Which of the following JQuery statements will hide spinner.gif in this HTML?


  1. <div id=”chatcontent”>
  2.  <img src=”spinner.gif” alt=”Loading…”/>
  3. </div>


  • $(“spinner.gif”).alt = -1;
  • $(“spinner.gif”).suppress();
  • $(“#chatcontent”).hide();
  • $(“img>spinner.gif”).hide();
  • $(“.chatcontent”).off();




Question 10)

What does the PHP function json_encode() do ?


  • Reads a JSON string representation and converts it to a PHP object or list
  • Takes a PHP object or list and serializes it into a JSON string representation
  • Encodes the less-than and greater-than characters to make a string safe for JSON
  • Encodes all non-printing characters with their hexadeciamal equivalents