Home / Past papers / MAD2 Quiz 2 / this paper

Consider the below javascript program.
```javascript
function data(d) {
return new Promise((res) => {
setTimeout(() => res('Your Data'), d * 1000)
})
}
function delta(d) {
return new Promise((res) => {
if (d > 3) {
setTimeout(() => res('delta'), d * 500)
} else {
return res('delta')
}
})
}
async function getData(d) {
const start = Date.now()
const _delta = await delta(d)
const _data = await data(d)
const end = Date.now()
const timeDifference = end - start
}
getData(4)
```
What will be the approximate value of the variable "timeDifference"?
Consider the following Vue application with javascript file “app.js” and markup file “index.html”. app.js:
```javascript
const Teams = {
template: `<ol><li v-for='team in
teams'>{{team.name}}</li></ol>`,
data() {
return {
teams: [
{ name: 'India', points: 827 },
{ name: 'Australia', points: 820 },
],
}
},
}
const Rankings = {
template: `<ol><li v-for='team in sortedTeams'>
{{team.name}}</li></ol>`,
data() {
return Teams.data()
},
computed: {
sortedTeams() {
return this.teams.sort((team1, team2) => {
return team1.points - team2.points // Statement 1
})
},
},
}
const router = new VueRouter({
routes: [
{ path: '/', component: Teams },
{ path: '/ranking', component: Rankings },
],
})
new Vue({
el: '#app',
template: `<div> <router-view /> </div>`,
router,
})
```
index.html:
```html
<div id="app"></div>
```
Suppose the application is running on "http://localhost:8080". If the developer wants to display the teams in descending order with respect to the points of team, for the URL "http://localhost:8080/#/ranking". What should be the value of return statement in "sortedTeams" computed property (Marked by statement1)?

Consider the following Vue application with javascript file "app.js" and markup file "index.html".
index.html:
```html
<body>
<div id="app"></div>
</body>
```
app.js:
```javascript
const Category = {
template:
`<div>{{$route.params.name}}<router-view></router-view></div>`,
}
const Error = {
template: `<div><slot> Page Not Found </slot></div>`,
}
const Product = {
template: `
<div>
<div v-if='filteredProducts.length > 0'>
<div v-for='product in filteredProducts'>
Name: {{product.name}}, Price: {{product.price}}
</div>
</div>
<Error v-else> No {{keyword}} Found </Error>
</div>`,
data() {
return {
keyword: this.$route.params.name,
products: [
{ category: 'Mobile', name: 'Samsung', price: '10K' },
```
```javascript
{
category: 'Mobile',
name: 'Apple',
price: '50K'
}, {
category: 'Laptop',
name: 'Lenovo',
price: '70K'
}, ],
},
computed: {
filteredProducts() {
return this.products.filter(
(product) =>
product.category.toLowerCase() ==
this.keyword.toLowerCase()
)
},
},
components: {
Error,
},
}
const router = new VueRouter({
routes: [{
path: '/category/:name',
component: Category,
children: [{
path: 'product',
component: Product
}],
}, {
path: '*',
component: Error
}, ],
})
new Vue({
el: '#app',
template: '<div><router-view /></div>',
router,
})
```
Suppose the application is running on "http://localhost:8080". What will be rendered by the browser for the URL "http://localhost:8080/#/"?
Page Not Found

laptop Name: Lenovo, Price: 70K

desktop No desktop Found

mobile Name: Samsung, Price: 10K Name: Apple, Price: 50K
Consider the following Vue application with javascript file “app.js” and markup file “index.html”.
Consider the following Vue application with javascript file “app.js” and markup file “index.html”. index.html:
```html
<body>
<div id="app"></div>
</body>
```
app.js:
```javascript
const Category = {
template:
`<div>{{ $route.params.name }}<router-view></router-view></div>`,
}
const Error = {
template: `<div><slot> Page Not Found </slot></div>`,
}
const Product = {
template: `
<div>
<div v-if='filteredProducts.length > 0'>
<div v-for='product in filteredProducts'>
Name: {{ product.name }}, Price: {{ product.price }}
</div>
</div>
<Error v-else> No {{keyword}} Found </Error>
</div>`,
data() {
return {
keyword: this.$route.params.name,
products: [
{ category: 'Mobile', name: 'Samsung', price: '10K' },
{ category: 'Mobile', name: 'Apple', price: '50K' },
{ category: 'Laptop', name: 'Lenovo', price: '70K' },
],
}
},
```
```javascript
computed: {
filteredProducts () {
return this.products.filter(
(product) =>
product.category.toLowerCase() ==
this.keyword.toLowerCase()
)
},
},
components: {
Error,
},
const router = new VueRouter({
routes: [
{
path: '/category/:name',
component: Category,
children: [{ path: 'product', component: Product }],
},
{ path: '*', component: Error },
],
})
new Vue({
el: '#app',
template: '<div><router-view /></router-view></div>',
router,
})
```
Suppose the application is running on “http://localhost:8080”. What will be rendered by the browser for the URL “http://localhost:8080/#/category/desktop/product”?
Page Not Found

laptop Name: Lenovo, Price: 70K

desktop No desktop Found

mobile Name: Samsung, Price: 10K Name: Apple, Price: 50K

Consider the following Vue application with javascript file "app.js" and markup file "index.html".
index.html
```html
<body>
<div id="app"></div>
</body>
```
app.js
```javascript
const Product = {
template: `<div>
<slot name="title">No title</slot>
<slot>No Description Given</slot>
<slot name="price">Flexible</slot>
</div>`,
}
new Vue({
el: '#app',
template: `
<Product>
<p>
<b>Lenovo Desktop</b>
8GB RAM, 512GB SSD
</p>
<template v-slot:price>
61K
</template>
</Product>`,
components: {
Product,
},
})
```
Suppose the application is running on "http://localhost:8080". What will be rendered by the browser for the URL "http://localhost:8080/#/"?
No title **Lenovo Desktop** 8GB RAM, 512GB SSD 61K

Lenovo Desktop 8GB RAM, 512GB SSD 61K

Lenovo Desktop 8GB RAM, 512GB SSD Flexible

No title **Lenovo Desktop** 8GB RAM, 512GB SSD Flexible

Consider the below javascript program, and predict the output, if executed.
```javascript
const data = {
count: 10
};
const newData = {}
Object.defineProperty(newData, 'count', {
get() {
return data.count;
},
set(newValue) {
data.count = newValue;
},
});
console.log("Before Update:", newData.count);
newData.count = 20;
console.log("After Update:", data.count);
```
Consider the following Vue application with javascript file “app.js” and markup file “index.html”. ```javascript
const Teams = {
template: `<ol><li v-for='team in
teams'>{{team.name}}</li></ol>`,
data() {
return {
teams: [
{ name: 'India', points: 827 },
{ name: 'Australia', points: 820 },
],
}
},
}
const Rankings = {
template: `<ol><li v-for='team in sortedTeams'>
{{team.name}}</li></ol>`,
data() {
return Teams.data()
},
computed: {
sortedTeams() {
return this.teams.sort((team1, team2) => {
return team1.points - team2.points // Statement 1
})
},
},
}
const router = new VueRouter({
routes: [
{ path: '/', component: Teams },
{ path: '/ranking', component: Rankings },
],
})
new Vue({
el: '#app',
template: `<div> <router-view /> </div>`,
router,
})
```
index.html:
```html
<div id="app"></div>
```
Suppose the application is running on "http://localhost:8080". What will be rendered by the browser for the url "http://localhost:8080/#/ranking"
Australia

India

1. Australia 2. India

1. India 2. Australia
Consider the following Vue application with javascript file “app.js” and markup file “index.html”.
Consider the following Vue application with javascript file “app.js” and markup file “index.html”. index.html:
```html
<body>
<div id="app"></div>
</body>
```
app.js:
```javascript
const Category = {
template:
`<div>{{ $route.params.name }}<router-view></router-view></div>`,
}
const Error = {
template: `<div><slot> Page Not Found </slot></div>`,
}
const Product = {
template: `
<div>
<div v-if='filteredProducts.length > 0'>
<div v-for='product in filteredProducts'>
Name: {{ product.name }}, Price: {{ product.price }}
</div>
</div>
<Error v-else> No {{keyword}} Found </Error>
</div>`,
data() {
return {
keyword: this.$route.params.name,
products: [
{ category: 'Mobile', name: 'Samsung', price: '10K' },
{ category: 'Mobile', name: 'Apple', price: '50K' },
{ category: 'Laptop', name: 'Lenovo', price: '70K' },
],
}
},
```
```javascript
computed: {
filteredProducts() {
return this.products.filter(
(product) =>
product.category.toLowerCase() ==
this.keyword.toLowerCase()
)
},
},
components: {
Error,
},
const router = new VueRouter({
routes: [{
path: '/category/:name',
component: Category,
children: [{
path: 'product',
component: Product
}],
}, {
path: '*',
component: Error
}, ],
})
new Vue({
el: '#app',
template: '<div><router-view /></div > ',
router,
})
```
Suppose the application is running on “http://localhost:8080”. What will be rendered by the browser for the URL “http://localhost:8080/#/category/mobile/product”?
Page Not Found

laptop Name: Lenovo, Price: 70K

desktop No desktop Found

mobile Name: Samsung, Price: 10K Name: Apple, Price: 50K

Consider the below javascript program, and predict the output, if executed.
```javascript
let x = 50;
const obj1 = {
x: 10,
func: function(x) {
console.log(x, "and", this.x)
}
}
const obj2 = {
x: 20,
func: function() {
console.log(x, "and", this.x)
obj1.func.call(this)
}
}
obj2.func.call(obj1)
```
Consider the below javascript program.
```javascript
async function result (x) {
const y = 6;
return new Promise (((reject, resolve) => {
if ((((x * 28) / (7 * x) - 2) == 1))
reject(y ** 2)
console.log("Inside Promise")
resolve(y ** 3)
}))
}
result(x).then(
rej => console.log("Promise rejected with the value", rej),
res => console.log("Promise resolved with the value", res)
).then(data => {
console.log("Data received is", data);
return "6"
}).finally(data => {
console.log("Data received is", data);
return "34"
}).then(data => console.log("Data received is", data))
```
Assuming the variable "x" passed to the "result" function is a whole number between 1 and 99 (including 1 and 99), what will be shown on the console, if the above program is executed?
Which of the following statement(s) is/are true regarding JavaScript language?
```javascript
function rule (num, obj) {
// some code here
}
rule(num, obj);
```
Consider the below Vue class bindings:
Code 1:
```html
<div :class="[isActive ? 'activeClass' : '', 'errorClass']"></div>
```
Code 2:
```html
<div :class="[{ 'activeClass': isActive }, 'errorClass']"></div>
```
Which of the following statement(s) is/are true?