Home / Past papers / MAD2 End Term / this paper

THIS IS QUESTION PAPER FOR THE SUBJECT "DIPLOMA LEVEL: MODERN APPLICATION DEVELOPMENT 2" ARE YOU SURE YOU HAVE TO WRITE EXAM FOR THIS SUBJECT? CROSS CHECK YOUR HALL TICKET TO CONFIRM THE SUBJECTS TO BE WRITTEN. (IF IT IS NOT THE CORRECT SUBJECT, PLS CHECK THE SECTION AT THE TOP FOR THE SUBJECTS REGISTERED BY YOU)
Which of the following shows the correct output if the javascript program written below is executed? ```javascript const arr = [1, 2, 3, 4, 5, 6, 7, 8] const arr1 = arr.map(r => r**3) const arr2 = arr1.filter(r => ((r % 3 == 2) || (r % 4 == 3))) console.log(arr2) ```
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose you open “index.html” file in a browser, and type the text “IIT Madras” in the text box shown (after removing the previous text, if any), and hard refresh the page twice, without clicking anywhere. What will be the value shown in the text box, and the “age” placeholder, respectively?index.html:
```html
<div id = "app">
<input v-model = "name" @input = "do_something">
<p>{{age}}</p>
</div>
<script scr = "app.js"></script>
```
app.js:
```javascript
new Vue({
el : "#app",
data : {
name : "#app",
age : 0,
},
mounted () {
try {
this.name = localStorage.getItem("name").split(" ")[0];
this.age = localStorage.getItem("name").split(" ")[1];
}
catch {
this.name = "Default";
this.age = "Default";
}
},
methods : {
do_something() {
localStorage.setItem("name", this.name);
localStorage.setItem("age", this.age);
}
}
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be the color of text rendered inside the div with ID “run”, if the user clicks on the button with text “Six”, 3 times and the button with text “Four”, 4 times?index.html:
```html
<html>
<head>
<style>
.onstrike {
color: blue;
}
</style>
</head>
<body>
<div id="app">
<div :class="{onstrike:changeStrike}" id="run">{{ run }}</div>
<button @click="run+=4">Six</button>
<button @click="run+=3">Four</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
</html>
```
app.js:
```javascript
new Vue({
el: '#app',
data: { run: 0 },
computed: {
changeStrike() {
return this.run % 2 === 0 ? true : false
},
},
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be the color and font-weight of the text “IITM online degree”?index.html:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.active {
color: blue;
}
.bold {
font-weight: bold;
}
</style>
</head>
<body>
<div id="app">
<Home class="bold" />
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</html>
```
app.js:
```javascript
Vue.component('Home', {
template: `<div class='active'>
IITM online degree
</div>`,
})
new Vue({
el: '#app',
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered on the screen?index.html:
```html
<body>
<div id="app">
<template v-for="cont in contributions">
<div>{{cont.player}}: {{cont.run}}/{{partnerShip}}</div>
</template>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
new Vue({
el: '#app',
data: {
partnerShip: 210,
contributions: [
{ player: 'Rohit', run: 100 },
{ player: 'Kohli', run: 110 },
],
},
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the div with ID “collections”, when the user selects the option “Type Two” ?```html
index.html:
<body>
<div id="app">
<div>
<select v-model="collType">
<option value="all">All</option>
<option value="typeOne">Type One</option>
<option value="typeTwo">Type Two</option>
</select>
</div>
<div id="collections">
<Numbers :numbers="numbers" v-show="collType==='all' "
/></Numbers>
<Numbers :numbers="typeOne" v-show="collType==='typeOne' "
/></Numbers>
<Numbers :numbers="typeTwo" v-show="collType==='typeTwo' "
/></Numbers>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
Vue.component('Numbers', {
template: `<div>
<span v-for="num in numbers">
{{num}}
</span></div>`,
props: ['numbers'],
})
new Vue({
el: '#app',
data: {
numbers: [2, 3, 4, 6, 7],
collType: 'typeOne',
},
computed: {
typeOne() {
return this.numbers.filter((num) => num % 2 === 0)
},
typeTwo() {
return this.numbers.filter((num) => num % 2 !== 0)
},
},
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose the user types “Apple” in the input box (after removing the existing text, if any). What will be rendered inside the div with ID “result”?index.html:
```html
<body>
<div id="app">
<custom-input v-model="searchText"></custom-input>
<div id="result">Searching for: {{searchText}}</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
Vue.component('custom-input', {
props: ['value'],
template: `
<input
v-bind:value="value"
v-on:input="$emit('input', $event.target.value)"
>
`
})
new Vue({
el: '#app',
data: { searchText: 'type something ...' },
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose the application is running on ‘http://127.0.0.1:8080/’. If the user visits the application for the first time and clicks on the button “Go to profile”, what will be displayed on the screen?index.html:
```html
<body>
<div id="app">
<router-view></router-view>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script
src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
const Profile = {
template: `<div> Welcome {{this.$route.params.name}}</div>`,
}
const Home = {
template: `<div> This is home page
<button @click='goToProfile'> Go to profile </button>
</div>`,
methods: {
goToProfile() {
this.$router.push({ name: 'profile', params: { name: 'narendra' } })
}
},
}
const router = new VueRouter({
routes: [
{ path: '/profile/:name', name: 'profile', component: Profile },
{ path: '/', component: Home },
],
})
new Vue({
el: '#app',
router,
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose the application is running on ‘http://127.0.0.1:8080/’. What will be rendered for the URL “http://127.0.0.1:8080/#/” ?index.html:
```html
<body>
<div id="app">
<router-view></router-view>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script
src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
</body>
```
```javascript
app.js:
const Movies = {
template: `<div><ul>
<div>Movies</div>
<router-view />
</ul></div>`,
}
const Error = {
template: `<div> Some Error</div>`,
}
const Hindi = {
template: `<div><ul>
<li v-for='movie in hindiMovies'>{{movie.name}}</li>
</ul></div>`,
data() {
return {
movies: [
{ name: 'Soley', language: 'hindi' },
{ name: 'Dexter', language: 'english' },
],
}
},
computed: {
hindiMovies() {
return this.movies.filter((movie) => {
return movie.language === 'english'
})
},
},
}
const router = new VueRouter({
routes: [
{
path: '/',
component: Movies,
children: [
{ path: 'hindi', component: Hindi },
{ path: '*', component: Error },
],
},
],
})
new Vue({
el: '#app',
router,
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the “custom-comp” component?index.html:
```html
<body>
<div id="app">
<custom-comp ref="custom" />
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
Vue.component('custom-comp', {
data() {
return { name: 'Rohit Sharma' }
},
template: `<div>Welcome {{name}}</div>`,
})
new Vue({
el: '#app',
mounted() {
this.$refs.custom.name = 'Virat Kohli'
},
})
```
Which of the following is the correct way to do class binding in Vue (to apply ‘classA’ on the div element), if the data object in the Vue constructor is defined as below? ```
data : {
classObj : {
classA : true,
classB : false
},
classA : true,
classB : false,
}
```
```html
<div :class="{classA : classA, classB : classB}"></div>
```
```html
<div :class="{classA : 'classA', classB : 'classB'}"></div>
```
```html <div :class = "classObj"></div> ```

```html
<div :class="{classObj}"></div>
```
Which of the following shows the correct output, if the javascript program written below is executed? ```javascript
new Promise((reject, resolve) => {
let a = 2 * 4 || 0 / 4;
let b = 3 * 4 && 0 / 4;
if (a > b) resolve(a);
else reject(b);
})
.then((d) => console.log("Passed:", d))
.catch((e) => console.log("Failed:", e))
.finally((d) => {
console.log("About to finish");
return "Over";
})
.then((d) => console.log("Finished !!", d));
```

Suppose you own a company where you want to hire candidates for an upcoming project on a deputation basis, and you have received a lot of applications. On discussing with your team members, you decided to shortlist the candidates based on the following 2 criteria:
1. The candidate must have at least 3 years of experience
2. The candidate's age must be less than 30 years
Fill in the `code1` & `code2`, which can be used in Vuex Store to update the "shortlisted" state variable with the objects of those candidates who satisfy the above-mentioned criteria. Also, predict the length of the state variable "shortlisted", after the mutation has completed its execution.
```javascript
const store = new Vuex.Store({
state : {
candidates : [
{
name : 'sample1',
age : 28,
experience : 2.5
},
{
name : 'sample2',
age : 35,
experience : 3.5
},
{
name : 'sample3',
age : 32,
experience : 3
},
{
name : 'sample4',
age : 38,
experience : 2
},
],
shortlisted : []
},
mutations : {
update_final(state, minimum) {
for (candidate of state.candidates)
code2
},
},
actions : {
send_task : function (context) {
code1
}
}
})
```
```
code1: this.$store.commit("update_final", 2);
code2: if (candidate.experience >= minimum && candidate.age < 30)
state.shortlisted.push(company)
Length: 3
```
```
code1: context.commit("update_final", 2);
code2: if (experience >= minimum && candidate.age < 30)
state.shortlisted.push(company)
```
Length: 2
```javascript
code1: this.$store.commit("update_final", 3);
code2: if (experience >= minimum && candidate.age < 30)
state.shortlisted.push(company)
```
Length: 3
```
code1: context.commit("update_final", 3);
code2: if (candidate.experience >= minimum && candidate.age < 30)
state.shortlisted.push(company)
```
Length: 2
Consider the following javascript program, and predict the output, if executed. ```javascript
let propA = 10;
const obj1 = {
propA : 20,
propB : function () {
console.log(propA, this.propA)
}
}
const obj2 = {
propA : 30,
propB : function () {
let func = () => console.log(propA, this.propA)
func()
}
}
obj2.propB.call(obj1);
```
Consider the following javascript program, and predict the output, if executed. Also, predict the minimum time taken (in seconds) to log the value “Executing” on the console. ```javascript
async function some () {
let promise = await new Promise((res, rej) => {
setTimeout(() => res("Execution Started"), 1000)
});;
let a = await promise;
let b = a.replace("e", "")
return new Promise ((rej, res) => {
let c = a + "\n" + b;
rej(c);
})
}
some().then(d => console.log(d)
).catch(e => console.log("Error"))
console.log("Executing")
```
Consider the following JavaScript program. What will be logged on to the console?```javascript
const p = function (t) {
return new Promise(((resolve, reject) => {
setTimeout((() => {
resolve(t)
}), t * 1000)
}))
}
data = []
asyncFunc = async function () {
p1 = await p(1)
p2 = await p(2)
data.push(p2)
data.push(p1)
}
asyncFunc()
data.push('Outer')
console.log(data)
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the div for ID “run”, if the user clicks on the button with text “Six”, 3 times and the button with text “Four”, 4 times?index.html:
```html
<html>
<head>
<style>
.onstrike {
color: blue;
}
</style>
</head>
<body>
<div id="app">
<div :class="{onstrike: changeStrike}" id="run">{{run}}</div>
<button @click="run+=4">Six</button>
<button @click="run+=3">Four</button>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
</html>
```
app.js:
```javascript
new Vue({
el: '#app',
data: { run: 0 },
computed: {
changeStrike() {
return this.run % 2 === 0 ? true : false
},
},
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the div with ID “collections”, when the browser loads the application for the first time?index.html:
```html
<body>
<div id="app">
<div>
<select v-model="collType">
<option value="all">All</option>
<option value="typeOne">Type One</option>
<option value="typeTwo">Type Two</option>
</select>
</div>
<div id="collections">
<Numbers :numbers="numbers" v-show="collType==='all'"></Numbers>
<Numbers :numbers="typeOne" v-show="collType==='typeOne'"></Numbers>
<Numbers :numbers="typeTwo" v-show="collType==='typeTwo'"></Numbers>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
Vue.component('Numbers', {
template: `<div>
<span v-for="num in numbers">
{{num}}
</span></div>`,
props: ['numbers'],
})
new Vue({
el: '#app',
data: {
numbers: [2, 3, 4, 6, 7],
collType: 'typeOne',
},
computed: {
typeOne() {
return this.numbers.filter((num) => num % 2 === 0)
},
typeTwo() {
return this.numbers.filter((num) => num % 2 !== 0)
},
}
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the router-view component of Movies component for the URL “http://127.0.0.1:8080/#/hindi”?index.html:
```html
<body>
<div id="app">
<router-view></router-view>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"
></script>
<script
src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"
></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
const Movies = {
template: `<div><ul>
<div>Movies</div>
<router-view />
</ul></div>`,
}
const Error = {
template: `<div> Some Error</div>`,
}
const Hindi = {
template: `<div><ul>
<li v-for='movie in hindiMovies'>{{ movie.name }}</li>
</ul></div>`,
data() {
return {
movies: [
{ name: 'Soley', language: 'hindi' },
{ name: 'Dexter', language: 'english' },
],
}
},
computed: {
hindiMovies() {
return this.movies.filter((movie) => {
return movie.language === 'english'
})
},
},
}
const router = new VueRouter({
routes: [
{
path: '/',
component: Movies,
children: [
{ path: 'hindi', component: Hindi },
{ path: '*', component: Error },
],
},
],
})
new Vue({
el: '#app',
router,
})
```Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Here’s a structured summary of core topics, concepts, and equations for the exam, followed by Mermaid knowledge graphs to visualize relationships.
int, char (unlike Java/C). Only number, string, boolean, null, undefined, symbol, bigint.const vs let:
const: Block-scoped, cannot be reassigned (but objects/arrays can be mutated).let: Block-scoped, reassignable.First-Order vs Higher-Order Functions:
map, filter).Closures:
Example:
function outer() {
let x = 10;
return function inner() { console.log(x); }; // Closure
}Promises & Async/Await:
.then(): Handles resolved promises..catch(): Handles rejections..finally(): Runs regardless of resolution/rejection.Async/Await: Syntactic sugar for promises.
async function foo() {
let result = await promise;
console.log(result);
}Truthiness & Operator Precedence:
|| (OR) returns the first truthy value.&& (AND) returns the first falsy value or the last truthy.Example:
let a = 2 * 4 || 0 / 4; // 8 (2*4 is truthy)
let b = 3 * 4 && 0 / 4; // 0 (0/4 is falsy)OAuth:
CORS (Cross-Origin Resource Sharing):
Access-Control-Allow-Origin, Access-Control-Allow-Methods.CSRF (Cross-Site Request Forgery):
{% csrf_token %}).Tokens vs Cookies:
localStorage).REST API Design:
/users instead of /getUsers).Cache-Control).Message Brokers (Redis + Celery):
Tasks:
task.delay(): Immediate execution.task.apply_async(countdown=10): Delayed execution (10 seconds).Credentials:
credentials: "omit": No cookies sent.credentials: "include": Send cookies (even cross-origin).credentials: "same-origin": Default (only same-origin cookies).Reactivity:
data(): Reactive state.computed: Cached derived state.methods: Functions (not cached).Directives:
v-model: Two-way binding.v-for: Loop rendering.v-show/v-if: Conditional rendering.Lifecycle Hooks:
mounted(): Runs after DOM insertion.created(): Runs after instance creation.Class/Style Binding:
<div :class="{ active: isActive, 'text-danger': hasError }"></div>
<div :class="classObj"></div> <!-- classObj: { active: true } -->$emit).<component :is="componentName">.routes array.:id in paths (e.g., /user/:id).*): Must be last in the routes array (matches unmatched paths).Example:
mutations: {
updateList(state, payload) {
state.list = payload;
}
},
actions: {
fetchData({ commit }) {
api.getData().then(data => commit('updateList', data));
}
}v-model: Binds to localStorage if manually implemented.ref: Access DOM elements or child components.v-model with :value + @input.setTimeout: Non-blocking delay.Promise Chaining:
promise
.then(data => console.log(data))
.catch(err => console.error(err))
.finally(() => console.log("Done"));Arrow Functions & this:
this from the parent scope.this.Logical OR (||) & AND (&&):
a || b → Returns a if truthy, else b.a && b → Returns a if falsy, else b.Promise Resolution:
resolve(value) → .then(value => ...).reject(error) → .catch(error => ...).javascript async function foo() { let result = await promise; // Pauses until promise resolves return result; } ``Array Methods:
map: Transform array → new array.filter: Return subset based on condition.Example:
const squares = [1, 2, 3].map(x => x ** 2); // [1, 4, 9]
const evens = [1, 2, 3].filter(x => x % 2 === 0); // [2]