Web Application Development with JavaScript and MongoDB | Week 3
Graded Quiz
1. If you see a template event listener that looks like this:
Template.jsclicker.events({ "click .js-clicker":function(){ }})
What class would you expect to see in the HTML tag that triggers the event?
js-clicker
jsclicker
None of the above
click
2. What is a very common reason for seeing the error message ‘Uncaught syntax error: Unexpected token Y’?
You have not put commas between the items in a property set.
You have accidentally typed a Y.
A well known bug in the Meteor framework.
You have not tied your shoelaces.
3. You have defined a method called testMethod. Which will happen if you call the following code in an event listener?
Meteor.call('testMethod', function(){
console.log('method callback!');
})
console.log('After the method!');
The method will not be invoked as methods do not take callbacks.
It will print ‘After the method!’ then ‘method callback!’
The method will not call the callback, so it will only print ‘After the method!’
It will print ‘method callback!’ then ‘After the method!’
4. You have a template that displays a list of documents from a collection. It has an event listener as follows:
Template.documents.events({ 'click .js-load-document':function(event){
// which variable would you access?
}})
Inside the event listener function, how would you access the data context for the template within which the event was triggered?
this
Documents.findOne()
Event.target
$(event.target).data()
5. In the template, you have the following code:
<input type="checkbox" id="myCheckbox" class="myCheckbox">
In the javascript code, the following event listener has been defined:
Template.docMeta.events({ "click #myCheckbox":function(event){
console.log("toggle!");
}})
Which of the following are true? (select all that apply)
In the event listener, event.target.checked tells you the state of the checkbox.
The selector could also be ‘.myCheckbox’.
In the event listener, event.target.checked will have the value true or false.
The event listener selector is wrong. The selector has to be ‘.myCheckbox’.
6. Where could the following code be placed in a Meteor application to ensure that it only runs on the server? (select all that apply)
Meteor.publish("documents", function(){ return Documents.Find({});})
In an isClient block.
In an isServer block.
In a js file in the server folder.
In a js file in the private folder.
7. An `or’ filter has 4 clauses, e.g.:
$or:[ {test1:true}, {test2:true}, {test3:true}, {test4:true}]
How many of the tests need to be true for an item in a collection to match the filter?
4
1
3
2
* The material and content uploaded on this website are for general information and reference purposes only.
Please do it by your own first!