Single Page Web Applications with AngularJS Week 2 Quiz

Course Name: Single Page Web Applications with AngularJS

Course Link: Single Page Web Applications with AngularJS

These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 10

Question 1
In the following snippets of code, the ‘lowered’ variable ends up with the exactly the same value:

Snippet #1:

var output = $filter('lowercase');
var lowered = output("GIVE ME COOKIES NOW!");

Snippet #2:

var lowered = $filter('lowercase')("GIVE ME COOKIES NOW!");

True
False

Answer: True


Question 2
Assuming value is a .23, what will the following snippet of code produce?

{{ value | currency : '%' : 3 }}

It will produce an error.
23
$.23%
%0.230
%.230

Answer: %0.230


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 11

Question 1
The name of the function that implements the filter factory function must contain the word “Factory”

True
False

Answer: False


Question 2
Assuming ‘CustomFilterFactory’ function is properly defined, the following is a valid filter declaration:

angular.module('app', [])
.filter('custom filter', CustomFilterFactory);

True
False

Answer: False


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Question 3
Given the following filter declaration:

angular.module('app', [])
.filter('hello', CustomFilterFactory);

What is the correct way to inject it into a controller function ‘Ctrl’?

Answer:

Ctrl.$inject = ['helloFilter'];
function Ctrl (helloFilter) {
  ...
}

Quiz 12

Question 1
If one of the watchers detected a change, what’s the least number of times that the Digest Loop will run in total?

1
2
At least once.
8

Answer: 2


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 13

Question 1
How many watchers does Angular setup for the following snippet of code?

<input type="text" ng-model="value">
<div>{{ value + '!' }}</div>
<button ng-click="getValue()">Get Value</button>

0
1
2
3
4

Answer: 2

See also  Single Page Web Applications with AngularJS Week 3 Quiz

These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 14

Question 1
One-time binding improves performance because it never sets up an Angular watch that the Digest Cycle needs to execute.

True
False

Answer: False


Question 2
How many watches remain after the user clicks the button, considering this snippet:

<div>{{ ::value }}</div>
<button ng-click="value = 3">Get Value</button>

0
1
2

Answer: 0


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 15

Question 1
Assuming ‘items’ is an array of objects like the following:

{
  name: 'Yaakov',
  occupation: 'Professional Cookie Eater'
}

Identify invalid code below.

Answer:

<div ng-repeat="item in items">
  name: {{ items.item.name }} <br>
  occupation: {{ items.item.occupation }}
</div>

These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 16

Question 1
Given the following code snippet, what will be the output of the statement on line 6.

var student1 = {
  message: "I LOVE this course!"
};
 
var student2 = Object.create(student1);
console.log(student2.message);

undefined
empty string or “”
I LOVE this course!
Uncaught ReferenceError: message is not defined

Answer: I LOVE this course!


Question 2
Given the following code snippet, what will be the output of the statement on line 11.

var student1 = {
  message: "I LOVE this course!"
};
 
var student2 = Object.create(student1);
student2.getMessage = function () {
  this.message = "Student 1 was paid off by Yaakov to say that!";
  return this.message;
};
var coverUp = student2.getMessage();
console.log(student2.message);

I LOVE this course!
undefined
Student 1 was paid off by Yaakov to say that!

Answer: Student 1 was paid off by Yaakov to say that!


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Question 3
Given the following function, how must this function be called such that the output of the function is an object with the property name whose value is “Yaakov”?

function Person(name) {
  this.name = name;
}

Answer:

var p = new Person("Yaakov");

Quiz 17

Question 1
True or false: given the following code snippet, the code on line 3 causes the Javascript engine to go up the prototype chain.

<div ng-controller="Controller1 as ctrl1">
  <div ng-controller="Controller2 as ctrl2">
    {{ ctrl1.name }}
  </div>
</div>

True
False

See also  Single Page Web Applications with AngularJS Week 3 Quiz

Answer: True


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 18

Question 1
In the following code snippet, the CustomService function will be treated as a function constructor by the AngularJS framework.

angular.module("MyApp")
.service('CustomService', CustomService);
...
...

True
False

Answer: True


Question 2
What is a Singleton?

AngularJS component that can’t find its soulmate.😢
It’s a Design Pattern that is a central place for producing objects.
It’s a Design Pattern that restricts the object to always having a single instance.
It’s a Design Pattern used exclusively for server-side programming

Answer: It’s a Design Pattern that restricts the object to always having a single instance.


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 19

Question 1
When creating a service with the .factory() method, it is ultimately the AngularJS framework that creates the function/object that is the service.

True
False

Answer: False

Question 2
The .factory() method is limited to producing only Singleton Services. It can’t simply produce some object we want to use in our application.

True
False

Answer: False


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


Quiz 20

Question 1
The function passed into angular.module(…).config(MyFunction) is guaranteed to run before services, factories, or controllers are created.

True
False

Answer: True


Question 2
Fill in:
To configure a service, it must be injected into the function passed into the .config() function with the extra string “___1___” appended to the ___2___.

1: Config
2: Module name
1: Provider
2: Name of the function the project was declared with
1: Provider
2: String name the provider was declared with. (passed into .provider as the first argument)

See also  Single Page Web Applications with AngularJS Week 4 Quiz

Answer: 1: Provider
2: String name the provider was declared with. (passed into .provider as the first argument)


Quiz 21

Question 1
The ng-if=”value” directive inserts “display: none” on the element it’s declared on if the ‘value’ evaluates to ‘false’, hiding the element.

True
False

Answer: False


These are Single Page Web Applications with AngularJS Week 2 Quiz Answers


More Weeks of the course: Click Here

More Coursera courses: https://progiez.com/coursera

Single Page Web Applications with AngularJS Week 2 Quiz