JavaScript, jQuery, and JSON Coursera Quiz Answers

JavaScript, jQuery, and JSON Week 01 Quiz Answers

Q1. Where does the following JavaScript code execute?

<p>One Paragraph</p> 
<script type="text/javascript"> 
document.write("<p>Hello World</p>") 
</script> 
<p>Second Paragraph</p>
  • In the database server
  • In the browser
  • In the network
  • In the web server

Q2. What happens when JavaScript runs the alert() function?

  • JavaScript checks to see if there are any unprocessed events
  • JavaScript execution is paused and a dialog box pops up
  • A message is sent back to the PHP code to be logged on the server
  • JavaScript pops up a dialog box and execution continues until the </alert> tag is encountered

Q3. Which of the following is not a way to include JavaScript in an HTML document?

  • By including the code the <?javascript and ?\> tags
  • By including the code between <script> and </script> tags
  • On a tag using an attribute like onclick=””
  • By including a file containing JavaScript using a tag

Q4. In the following code, what does the “return false” accomplish?

<a href="js-01.htm" onclick="alert('Hi'); return false;">Click Me</a>
  • It is necessary to insure that the onclick code is at least two lines of code
  • It sets the default for the alert() dialog box
  • It suppresses the pop up dialog that asks “Are you sure you want to navigate away from this page?”
  • It keeps the browser from following the href attribute when “Click Me” is clicked

Q5. What happens in a normal end-user’s browser when there is a JavaScript error?

  • JavaScript logs the error to the PHP error log
  • JavaScript skips the line in error and continues executing after the next semicolon (;)
  • JavaScript prints a traceback indicating the line in error
  • Nothing except perhaps a small red error icon that is barely noticeable

Q6. Where can a developer find which line in a web page of JavaScript file is causing a syntax error?

  • Do a “View Source” to see the HTML source code
  • In the developer console in the browser
  • By looking at a file on the hard disk of the system where the browser is running
  • In the PHP error log

Q7. What does the following JavaScript do?

console.log("This is a message");
  • Puts the message in the PHP console log
  • Puts the message in the browser console and pauses JavaScript execution
  • Puts the message in the browser developer console and continues JavaScript execution
  • Sends the message to console.log.com

Q8. Which of the following is not a valid comment in JavaScript

  • # This is a comment
  • // This is a comment
  • /* This is a comment */

Q9. Which of the following is not a valid JavaScript variable name?

  • _data
  • 3peat
  • $_DATA
  • $data
  • $_data

Q10. What is the difference between strings with single quotes and double quotes in JavaScript?

  • Double quoted strings so variable substitution for variables that start with dollar sign ($)
  • Double quotes strings cannot be used in JavaScript
  • Single quoted strings do not treat \n as a newline
  • There is no difference

Q11. What does the following JavaScript print out?

toys = ['bat', 'ball', 'whistle', 'puzzle', 'doll'];console.log(toys[1]);
  • doll
  • whistle
  • puzzle
  • bat
  • ball

Q12. What value ends up in the variable x when the JavaScript below is executed?

x = 27 % 2;
  • 2
  • 0
  • 54
  • 13.5
  • 27
  • 1

Q13. What is the meaning of the “triple equals” operator (===) in JavaScript?

  • That the values being compared are the same without any type conversion
  • Both sides of the triple equals operator are converted to boolean before comparison
  • Both sides of the triple equals operator are converted to string before comparison
  • Both sides of the triple equals operator are converted to integers before comparison

Q14. How do you indicate that a variable reference within a JavaScript function is a global (i.e. not local) variable?

  • Use the keyword “global” to declare the variable in the function
  • Use the keyword “global” when declaring the variable outside the function
  • Nothing, simply declare the variable globally before the function definition in the code
  • Use the keyword “var” to declare the variable in the function

JavaScript, jQuery, and JSON Week 02 Quiz Answers

Q1. Which of the following is a template that defines the shape of an object that is created?

  • Method
  • Message
  • Inheritance
  • Instance
  • Class

Q2. Which of the following describes a feature which we would expect from a programming language that supported first class functions?

  • The ability to have a variable number of parameters when calling a function
  • The ability to define a function and assign the function to a variable
  • The ability for a function not to return a value (i.e. void functions)
  • The ability to omit parameters and have the omitted parameters default to a value
  • The ability to return a value from a function

Q3. What is the keyword / predefined variable that is used in a JavaScript class definition to refer to the “current instance” of the class?

  • $this
  • _self
  • self
  • me
  • this

Q4. What do these two statements in JavaScript accomplish?

data.stuff = "hello"; 
data['stuff'] = "hello";
  • The second statement is a syntax error in JavaScript
  • These two statements accomplish the same thing
  • The first statement creates an object and the second creates a dictionary
  • The first statement is a syntax error in JavaScript

Q5. How is the constructor defined in JavaScript class compared to how the constructor is defined in a PHP class?

  • The PHP constructor method is called __construct() and the JavaScript constructor method is called construct()
  • A PHP constructor is a method named __construct() and a JavaScript constructor is code in the outer function definition
  • The PHP and JavaScript constructor patterns are the same
  • JavaScript does not support the notion of running a “constructor” when objects are created.

JavaScript, jQuery, and JSON Week 03 Quiz Answers

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

$(document).ready(function(){
 window.console && console.log('Hello JQuery..');
});
  • Register a function that will be called when the HTML document is completely loaded
  • Clear the browser window so drawing can start in the upper left hand corner
  • Ascertain if the document is ready to load
  • Enable the retrieval of data in the JSON format

Q2. What portion of the DOM (Document Object Model) will be affected by the following JQuery statement:1$('#para').css('background-color', 'red');

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

Q3. What does the following JQuery code do

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

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

<p id="p">two
  <input type="text" name="one" value="three" title="four">
  <input type="text" name="five" class="p" value="p">
</p>
<script>
$('#p').find('input[name="one"]').val();
</script>
 
  • one
  • three
  • four
  • two
  • five

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

  • url
  • boolean
  • string
  • integer
  • array

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

data = {'one':'two', 'three': 4,
  'five' : [ 'six', 'seven' ],
  'eight' : { 'nine' : 10, 'ten' : 11  }
}
  • alert(data.five[0])
  • alert(data.eight.nine)
  • alert(five)
  • alert(data[‘six’])
  • alert(five.six)

Q7. What would the following JavaScript print out?


data = {'one':'two', 'three': 4,
  'five' : [ 'six', 'seven' ],
  'eight' : { 'nine' : 10, 'ten' : 11  }
};
alert(data.eight.nine);
  • six
  • nine
  • 10
  • seven
  • 11

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

$.getJSON('json.php', function(data) {
    $("#back").html(data.first);
    window.console && console.log(data);
 });
  • A string that is the entire HTTP response of the output from the script json.php
  • All of the tags from the DOM with a class attribute of “back”
  • The tag in the DOM that has an id attribute of “first”
  • Either a JavaScript object or list depending on the returned output of the script json.php

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

<div id="chatcontent">
 <img src="spinner.gif" alt="Loading..."/>
</div>
  • $(“spinner.gif”).suppress();
  • $(“spinner.gif”).alt \= \-1;
  • $(“img>spinner.gif”).hide();
  • $(“#chatcontent”).hide();
  • $(“.chatcontent”).off();

Q10. What does the PHP function json_encode() do ?

  • Encodes the less\-than and greater\-than characters to make a string safe for JSON
  • Takes a PHP object or list and serializes it into a JSON string representation
  • Reads a JSON string representation and converts it to a PHP object or list
  • Encodes all non\-printing characters with their hexadeciamal equivalents
Get All Course Quiz Answers of Web Applications for Everybody Specialization

Building Web Applications in PHP Coursera Quiz Answers

Introduction to Structured Query Language (SQL) Quiz Answers

Building Database Applications in PHP Coursera Quiz Answers

JavaScript, jQuery, and JSON Coursera Quiz Answers

Team Networking Funda
Team Networking Funda

We are Team Networking Funda, a group of passionate authors and networking enthusiasts committed to sharing our expertise and experiences in networking and team building. With backgrounds in Data Science, Information Technology, Health, and Business Marketing, we bring diverse perspectives and insights to help you navigate the challenges and opportunities of professional networking and teamwork.

Leave a Reply

Your email address will not be published. Required fields are marked *