Quiz Space

May 2023 term · Modern Application Development II · BSCS2006

Modern Application Development II Quiz 1: 16 July 2023 (May 2023 term)

The IIT Madras BS Modern Application Development II (MAD 2) Quiz 1 paper sat on 16 Jul 2023, in the May 2023 term: 16 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
16
Marks
50
Duration
120 min
MSQ
3
MCQ
13

Updated

Official paper: IIT M FOUNDATION AN2 EXAM QPF2 16 JULY 2023 · No negative marking.

Question 1

+2 marksOne or more correct options

Suppose you are given the below HTML.

Which of the following code(s) can be used to access the HTML paragraph element at “Statement 1” using JavaScript?

Select all that apply.

  1. A

    document.getElementById(“id2”)

  2. B

    document.getElementById(“id1”)

  3. C

    document.getElementByClassName(“class1”)

  4. D

    document.getElementByClassName(“class1”)[0]

Show answer

Correct answers

  • B

    document.getElementById(“id1”)

  • D

    document.getElementByClassName(“class1”)[0]

Question 2

+2 marksOne or more correct options

Which of the following is/are not example(s) of system level state?

Select all that apply.

  1. A

    Gmail Inbox of a given user

  2. B

    User database of LinkedIn

  3. C

    YouTube Recommendations after signing in

  4. D

    Countdown timer in a game

Show answer

Correct answers

  • A

    Gmail Inbox of a given user

  • C

    YouTube Recommendations after signing in

  • D

    Countdown timer in a game

Question 3

+2 marksOne or more correct options

Which of the following statements is/are true?

Select all that apply.

  1. A

    Lexical scope describes how the parser resolves the variable name in case of nested functions.

  2. B

    Inner functions have access to the outer functions variables in JavaScript.

  3. C

    Inner functions do not have access to the outer functions variables in JavaScript.

  4. D

    None of these.

Show answer

Correct answers

  • A

    Lexical scope describes how the parser resolves the variable name in case of nested functions.

  • B

    Inner functions have access to the outer functions variables in JavaScript.

Question 4

+2 marksOne correct option
  1. A

    This tag is used to insert the JavaScript code to be run when the page opens.

  2. B

    This tag is used to insert HTML, if the browser doesn’t support script or is disabled.

  3. C

    This tag, if used in a web page, does not let the browser cache the page contents.

  4. D

    None of these

Show answer

Correct answer

  • B

    This tag is used to insert HTML, if the browser doesn’t support script or is disabled.

Question 5

+3 marksOne correct option

Consider the below JavaScript program, and predict the output, if executed.

javascript
class Person {
constructor(name) {
this.name = name;
this.age = 23;
}
static fromJson(obj) {
let new_obj = new Person(obj.name);
new_obj.sound = obj.sound;
return new_obj;
}
}
result = new Person('Abhi');
console.log(Person.fromJson(JSON.parse(JSON.stringify(result))).constructor
.name);
  1. A

    Person

  2. B

    Abhi

  3. C

    constructor

  4. D

    Reference Error

Show answer

Correct answer

  • A

    Person

Question 6

+3 marksOne correct option

Consider the below JavaScript program, and predict the output, if executed.

javascript
let x = 50;
const obj1 = {
x : 10,
func : function () {
console.log(this.x)
}
}
const obj2 = {
x : 20,
func : () => {
function abc () {
console.log(x, "and", this.x)
obj1.func.call(this)
}
abc()
}
}
obj2.func()
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 7

+3 marksOne correct option

Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”.

index.html:

html
<body>
<div id = "app">
<ol>
<li v-for="item in items" :key="item.id">{{ item.name }}</li>
</ol>
</div>
</body>
<script src = "app.js"> </script>

app.js:

javascript
const a = new Vue({
el : '#app',
data : {
items: [
{ id: 1, name: 'App Dev I Theory' },
{ id: 2, name: 'App Dev I Project' },
{ id: 3, name: 'App Dev II Theory' },
{ id: 4, name: 'App Dev II Project' }
]
},
})

Suppose you open the “index.html” file in a browser, what will be rendered by the browser?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 8

+3 marksOne correct option

Consider the below Vue application with markup file “index.html”, and javaScript file “app.js”.

index.html:

html
<body>
<div id = "app">
<ol>
<li v-for="item in items" :key="item.id">
<blog-post :post-title = "item.name" :post-content =
"item.message"> </blog-post>
</li>
</ol>
</div>
</body>
<script src = "app.js"> </script>

app.js:

javascript
Vue.component('blog-post', {
props: {
'postTitle' : String,
'postContent' : String
},
template: `
<div>
<h3>{{ postTitle }}</h3>
<p>{{ postContent }}</p>
</div>
`
})
const a = new Vue({
el : '#app',
data : {
items: [
{ id: 1, name: 'IITM BS', message: "The World's first
4-year BS degree in DS and Applications"},
{ id: 2, name: 'IITM ES', message: "Learn Electronic
Systems from top-notch IIT Madras faculty"},
{ id: 3, name: 'NPTEL', message: "Online Learning
Initiatives by IITs and IISc"}
]
},
})

Suppose you open the “index.html” file in a browser, what will be rendered by the browser?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 9

+3 marksOne correct option

Consider the following JavaScript program.

javascript
function doSomeThing(n, ...params) {
return params
.map((x) => {
return x ** n
})
.sort()
}
console.log(doSomeThing(2, 5, 10))

What will be logged on to console?

  1. A

    [5, 10]

  2. B

    [25, 100]

  3. C

    [10, 5]

  4. D

    [100, 25]

Show answer

Correct answer

  • D

    [100, 25]

Question 10

+3 marksOne correct option

Consider the following JavaScript program.

javascript
function coolerPlace({...obj }) {
let tmp = 0
let cty = null
Object.entries(obj).forEach(([city, temp]) => {
if (temp > tmp) {
cty = city
}
})
return cty
}
console.log(coolerPlace({ UP: 37, Delhi: 40 }))

What will be logged on to console?

  1. A

    UP

  2. B

    Delhi

  3. C

    37

  4. D

    40

Show answer

Correct answer

  • B

    Delhi

Question 11

+3 marksOne correct option

Consider the following JavaScript program.

javascript
const addres1 = {
state: 'Tamil Nadu',
city: 'Chennai',
place: 'IIT Madras',
getAddress() {
return `State: ${this.state}, city: ${this.city},
place:${this.place}`
},
}
const addres3 = {
place: 'Taramani',
__proto__: addres1,
}
console.log(addres3.getAddress())

What will be logged on to console?

  1. A

    State: Tamil Nadu, city: Chennai, place: Taramani

  2. B

    State: Tamil Nadu, city: Chennai, place: IIT Madras

  3. C

    State: , city: , place:Taramani

  4. D

    State: , city: , place:

Show answer

Correct answer

  • A

    State: Tamil Nadu, city: Chennai, place: Taramani

Question 12

+3 marksOne correct option

Consider the following JavaScript program.

javascript
let x = 1
let y = 2
{
let x = 4
let y = 5
}
function outer() {
function inner() {
return x + y
}
return inner
}
console.log(outer()())

What will be logged on to console?

  1. A

    9

  2. B

    3

  3. C

    NaN

  4. D

    undefined

Show answer

Correct answer

  • B

    3

Question 13

+4.5 marksOne correct option

Consider the below JavaScript program, and predict the output. Also, predict the number of times the while loop will run.

javascript
function do_something(arr, val){
var i1 = 0;
var i2 = arr.length;
while(i2 > i1){
var i3 = Math.floor((i1 + i2)/2);
if(val > arr[i3]){
i1 = i3 + 1;
}
else if(val < arr[i3]){
i2 = i3;
}
else{
return true;
}
}
return false;
}
result = do_something([3, 6, 34, 39, 48, 56, 78, 87], 40)
console.log(result)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 14

+4.5 marksOne correct option

Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”.

app.js

javascript
new Vue({
el: '#app',
template: `<div> The nearest city to you is: {{minDistance}}
</div>`,
data: {
userCoordinate: [1, 2],
allCooridates: [
{ name: 'City1', coodinate: [1, 7] },
{ name: 'City2', coodinate: [2, 4] },
{ name: 'City3', coodinate: [3, 5] },
{ name: 'City4', coodinate: [1, 4] },
],
},
methods: {
calculateDistance(x, y) {
return Math.abs(x[0] - y[0]) + Math.abs(x[1] - y[1])
},
},
computed: {
minDistance() {
let minDist = Infinity
let city = null
this.allCooridates.forEach((cord) => {
let d = this.calculateDistance(cord.coodinate,
this.userCoordinate)
if (d < minDist) {
minDist = d
city = cord.name
}
})
return city
},
},
})
  1. A

    The nearest city to you is: City1

  2. B

    The nearest city to you is: City2

  3. C

    The nearest city to you is: City3

  4. D

    The nearest city to you is: City4

Show answer

Correct answer

  • D

    The nearest city to you is: City4

Question 15

+4.5 marksOne correct option

Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”.

app.js

javascript
new Vue({
el: '#app',
template: `<div>
<input type='text' v-model='num'></input>
<div id='lon'>Lucky or not? {{lucky?'Lucky':'Not Lucky'}}</div>
</div>`,
data: {
num: 1,
prev: 0,
current: 1,
lucky: false,
},
watch: {
num(num1, num2) {
if (num1 == '') {
return
}
this.prev = this.current
this.current = Number(num1)
this.current > this.prev ? (this.lucky = true) : (this.lucky =
false)
},
},
})

index.html

html
<div id="app"></div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="./app.js"></script>

Suppose the application is running on ‘http://localhost:8080’. Suppose the user inputs 7 and then 5. What will be rendered inside the div with id ‘lon’?

  1. A

    Lucky or not? Lucky

  2. B

    Lucky or not? Not Lucky

  3. C

    Lucky or not?

  4. D

    None of these

Show answer

Correct answer

  • B

    Lucky or not? Not Lucky

Question 16

+4.5 marksOne correct option

Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”.

app.js

javascript
const Sender = {
template: `<div> Message: <input type='text'
v-model='message'></input> </div>`,
data() {
return {
message: null,
}
},
watch: {
message(msg) {
this.$emit('newmsg', this.message)
},
},
}
const Receiver = {
template: '<div id="msg"> {{msg}} </div>',
props: ['msg'],
}
new Vue({
el: '#app',
template: `<div>
<Sender @newmsg = 'updateMessage'/>
<Receiver :msg='message' />
</div>`,
data: {
message: null,
},
methods: {
updateMessage(msg) {
this.message = msg.split('').reverse().join('').toUpperCase()
},
},
components: {
Sender,
Receiver,
},
})

index.html

html
<div id="app"></div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="./app.js"></script>

Suppose the application is running on ‘http://localhost:8080’. If the user inputs ‘hello’ inside the input box, what will be rendered inside the div with ID ‘msg’?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C