MAD Study Hub

Home / Past papers / MAD2 Quiz 1 / this paper

IIT M FOUNDATION AN4 EXAM QPF4 16 JULY 2023 - 16 Jul 2023

MAD2 Quiz 116 questions50 marks13 MCQ · 3 MSQFoundation / QPF4
Elapsed 00:00
Q1MSQ2 marksselect all that apply
Suppose you are given the below HTML. question figure 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?
Text of the picture (copyable)
```html
<body>
    <p id = "id1" class = "class1">Content A</p> <!-- Statement 1 -->
    <p id = "id2" class = "class1">Content B</p> <!-- Statement 2 -->
</body>
```
  1. document.getElementById(“id2”)
  2. document.getElementById(“id1”)
  3. document.getElementByClassName(“class1”)
  4. document.getElementByClassName(“class1”)[0]
Q2MSQ2 marksselect all that apply
Which of the following is/are not example(s) of system level state?
  1. Gmail Inbox of a given user
  2. User database of LinkedIn
  3. YouTube Recommendations after signing in
  4. Countdown timer in a game
Q3MSQ2 marksselect all that apply
Which of the following statements is/are true?
  1. Lexical scope describes how the parser resolves the variable name in case ofnested functions.
  2. Inner functions have access to the outer functions variables in JavaScript.
  3. Inner functions do not have access to the outer functions variables inJavaScript.
  4. None of these.
Q4MCQ2 marks
question figure
Text of the picture (copyable)
Which of the following statements is correct regarding "<noscript>" tag in HTML?
  1. This tag is used to insert the JavaScript code to be run when the page opens.
  2. This tag is used to insert HTML, if the browser doesn’t support script or isdisabled.
  3. This tag, if used in a web page, does not let the browser cache the pagecontents.
  4. None of these
Q5MCQ3 marks
Consider the below JavaScript program, and predict the output, if executed. question figure Consider the below JavaScript program, and predict the output, if executed.
Text of the picture (copyable)
```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. Person
  2. Abhi
  3. constructor
  4. Reference Error
Q6MCQ3 marks
Consider the below JavaScript program, and predict the output, if executed. question figure Consider the below JavaScript program, and predict the output, if executed.
Text of the picture (copyable)
```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. question figure
    text
    50 and 20
    10
  2. question figure
    text
    50 and 20
    undefined
  3. question figure
    text
    50 and undefined
    undefined
  4. question figure
    text
    50 and undefined
    10
Q7MCQ3 marks
Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. Suppose you open the “index.html” file in a browser, what will be rendered by the browser?
Text of the picture (copyable)
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' }
        ]
    },
})
```
  1. question figure
    text
    App Dev II Project
    App Dev II Theory
    App Dev I Project
    App Dev I Theory
  2. question figure
    text
    App Dev I Theory
    App Dev I Project
  3. question figure
    text
    App Dev II Theory
    App Dev II Project
  4. question figure
    text
    App Dev I Theory
    App Dev I Project
    App Dev II Theory
    App Dev II Project
Q8MCQ3 marks
Consider the below Vue application with markup file “index.html”, and javaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and javaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and javaScript file “app.js”. Suppose you open the “index.html” file in a browser, what will be rendered by the browser?
Text of the picture (copyable)
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"}
        ]
    },
})
```
  1. question figure
    text
    1. IITM BS
    2. IITM ES
    3. NPTEL
  2. question figure
    text
    1. IITM BS
    The World's first 4-year BS degree in DS and Applications
    
    2. IITM ES
    Learn Electronic Systems from top-notch IIT Madras faculty
    
    3. NPTEL
    Online Learning Initiatives by IITs and IISc
  3. question figure
    text
    1. The World's first 4-year BS degree in DS and Applications
    2. Learn Electronic Systems from top-notch IIT Madras faculty
    3. Online Learning Initiatives by IITs and IISc
  4. question figure
    text
    A. NPTEL
    Online Learning Initiatives by IITs and IISc
    
    B. IITM ES
    Learn Electronic Systems from top-notch IIT Madras faculty
    
    C. IITM BS
    The World's first 4-year BS degree in DS and Applications
Q9MCQ3 marks
Consider the following JavaScript program. question figure Consider the following JavaScript program. What will be logged on to console?
Text of the picture (copyable)
```javascript
function doSomething(n, ...params) {
  return params
    .map((x) => {
      return x ** n
    })
    .sort()
}

console.log(doSomething(2, 5, 10))
```
  1. [5, 10]
  2. [25, 100]
  3. [10, 5]
  4. [100, 25]
Q10MCQ3 marks
Consider the following JavaScript program. question figure Consider the following JavaScript program. What will be logged on to console?
Text of the picture (copyable)
```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 }))
```
  1. UP
  2. Delhi
  3. 37
  4. 40
Q11MCQ3 marks
Consider the following JavaScript program. question figure Consider the following JavaScript program. What will be logged on to console?
Text of the picture (copyable)
```javascript
const address1 = {
    state: 'Tamil Nadu',
    city: 'Chennai',
    place: 'IIT Madras',
    getAddress() {
        return `State: ${this.state}, city: ${this.city}, place:${this.place}`
    },
}

const address3 = {
    place: 'Taramani',
    __proto__: address1,
}

console.log(address3.getAddress())
```
  1. State: Tamil Nadu, city: Chennai, place: Taramani
  2. State: Tamil Nadu, city: Chennai, place: IIT Madras
  3. State: , city: , place:Taramani
  4. State: , city: , place:
Q12MCQ3 marks
Consider the following JavaScript program. question figure Consider the following JavaScript program. What will be logged on to console?
Text of the picture (copyable)
```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() ())
```
  1. 9
  2. 3
  3. NaN
  4. undefined
Q13MCQ4.5 marks
Consider the below JavaScript program, and predict the output. Also, predict the number of times the while loop will run. question figure Consider the below JavaScript program, and predict the output. Also, predict the number of times the while loop will run.
Text of the picture (copyable)
```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. question figure
    text
    true
    The while loop will run 3 times
  2. question figure
    text
    false
    The while loop will run 4 times
  3. question figure
    text
    false
    The while loop will run 3 times
  4. question figure
    text
    true
    The while loop will run 4 times
Q14MCQ4.5 marks
Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”.
Text of the picture (copyable)
```javascript
app.js
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
    },
  },
})
```
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.
What will be rendered by the browser?
  1. The nearest city to you is: City1
  2. The nearest city to you is: City2
  3. The nearest city to you is: City3
  4. The nearest city to you is: City4
Q15MCQ4.5 marks
Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”.
Text of the picture (copyable)
```javascript
app.js
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. Lucky or not? Lucky
  2. Lucky or not? Not Lucky
  3. Lucky or not?
  4. None of these
Q16MCQ4.5 marks
Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”. question figure Consider the below Vue application with markup file “index.html”, and JavaScript file “app.js”.
Text of the picture (copyable)
```javascript
app.js
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. question figure
    text
    hello
  2. question figure
    text
    HELLO
  3. question figure
    text
    OLLEH
  4. question figure
    text
    olleh

Answer key

  1. Q1 (MSQ, 2 marks): B, D
  2. Q2 (MSQ, 2 marks): A, C, D
  3. Q3 (MSQ, 2 marks): A, B
  4. Q4 (MCQ, 2 marks): B
  5. Q5 (MCQ, 3 marks): A
  6. Q6 (MCQ, 3 marks): C
  7. Q7 (MCQ, 3 marks): D
  8. Q8 (MCQ, 3 marks): B
  9. Q9 (MCQ, 3 marks): D
  10. Q10 (MCQ, 3 marks): B
  11. Q11 (MCQ, 3 marks): A
  12. Q12 (MCQ, 3 marks): B
  13. Q13 (MCQ, 4.5 marks): C
  14. Q14 (MCQ, 4.5 marks): D
  15. Q15 (MCQ, 4.5 marks): B
  16. Q16 (MCQ, 4.5 marks): C

Concepts this paper tests

Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.

Summary of Core Topics, Concepts, Principles, and Equations

HTML and JavaScript

  1. Accessing HTML Elements with JavaScript

    • document.getElementById("id")
    • document.getElementsByClassName("className")
  1. JavaScript Classes and Static Methods

    • Class definition and constructor
    • Static methods and their usage

    ``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; } } ``

  1. JavaScript Scope and this Keyword

    • Lexical scope and variable resolution
    • Access to outer function variables by inner functions
    • Arrow functions and their scope

    ``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. JavaScript Functions and Parameters

    • Rest parameters and their usage
    • Mapping and sorting arrays

    ``javascript function doSomething(n, ...params) { return params .map((x) => { return x ** n }) .sort(); } ``

  1. JavaScript Objects and Prototypes

    • Object properties and methods
    • Prototypal inheritance

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

  1. JavaScript Binary Search

    • Binary search algorithm
    • Loop iterations and conditions

    ``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; } ``

Vue.js

  1. Vue.js Directives and Components

    • v-for directive for looping
    • Component definition and usage
    • Props and templates

    ``html <div id="app"> <ol> <li v-for="item in items" :key="item.id">{{ item.name }}</li> </ol> </div> ` `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' } ] } }); ``

  1. Vue.js Watchers and Data Binding

    • v-model for two-way data binding
    • Watchers for reactive changes

    ``javascript new Vue({ el: '#app', template: <div> <input type='text' v-model='num'></input> <div id='ion'>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) } }, }) ``

  1. Vue.js Component Communication

    • Emitting events and props
    • Parent-child component interaction

    ``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, }, }) ``