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, principles, and equations for the exam, followed by Mermaid knowledge graphs to visualize relationships.
number, string, boolean, null, undefined, symbol, BigInt (No int/char in JS).const vs let:
const: Block-scoped, cannot be reassigned (but objects/arrays can be mutated).let: Block-scoped, can be reassigned.First-Order vs Higher-Order Functions:
map, filter).Closures:
Promises & Async/Await:
.then(): Handles resolved promises..catch(): Handles rejections..finally(): Executes regardless of resolution/rejection.async/await: Syntactic sugar for promises.Arrow Functions vs Regular Functions:
this from the parent scope.this (dynamic binding).// Closure Example
function outer() {
let x = 10;
return function inner() { console.log(x); };
}
const closure = outer(); // x is preserved in closure.
// Promise Example
new Promise((resolve, reject) => {
if (success) resolve("Done");
else reject("Error");
})
.then(d => console.log(d))
.catch(e => console.log(e));
// Async/Await Example
async function fetchData() {
const data = await someAsyncTask();
console.log(data);
}
JAMStack:
REST API Design:
/users instead of /getUsers).Authentication/Authorization:
Access-Control-Allow-Origin).// CORS Header Example (Server-Side)
response.setHeader("Access-Control-Allow-Origin", "*");
// CSRF Token Example (Flask)
<form>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
</form>
// Local Storage Example
localStorage.setItem("key", "value");
const data = localStorage.getItem("key");
Directives:
v-model: Two-way data binding.v-for: Render lists.v-if/v-show: Conditional rendering.v-bind: Dynamic attributes (e.g., :class).v-on: Event handling (e.g., @click).Components:
Computed Properties vs Methods:
Vue Router:
vue-router.router-view: Renders matched components.router-link: Navigation links.Vuex (State Management):
Class/Style Binding:
:class="{ active: isActive }" (object syntax).:class="[classA, classB]" (array syntax).Lifecycle Hooks:
created, mounted, updated, destroyed.// Vue Component Example
Vue.component('my-component', {
props: ['message'],
template: `<div>{{ message }}</div>`
});
// Vuex Store Example
const store = new Vuex.Store({
state: { count: 0 },
mutations: {
increment(state) { state.count++; }
},
actions: {
incrementAsync({ commit }) {
setTimeout(() => commit('increment'), 1000);
}
}
});
// Vue Router Example
const router = new VueRouter({
routes: [
{ path: '/', component: Home },
{ path: '/about', component: About }
]
});
Server-Sent Events (SSE):
Message Brokers (Celery + Redis):
Tasks:
task.delay(): Immediate execution.task.apply_async(countdown=10): Delayed execution.// Webhook Example (Server-Side)
app.post('/webhook', (req, res) => {
console.log("Received:", req.body);
res.status(200).end();
});
// Celery Task Example (Python)
@celery.task
def send_email():
print("Sending email...")
### Delayed execution
send_email.apply_async(countdown=10)
Credentials in Fetch:
credentials: 'include': Send cookies in cross-origin requests.credentials: 'omit': Exclude cookies.credentials: 'same-origin': Default (send cookies for same origin).Request Methods:
GET, POST, PUT, DELETE, PATCH.Headers:
Content-Type: application/json, multipart/form-data.Authorization: Bearer <token>.// Fetch API Example
fetch('https://api.example.com/data', {
method: 'POST',
credentials: 'include', // Send cookies
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'value' })
})
.then(response => response.json())
.then(data => console.log(data));
CORS (Cross-Origin Resource Sharing):
Access-Control-Allow-Origin, Access-Control-Allow-Methods.CSRF (Cross-Site Request Forgery):
OAuth 2.0:
JWT (JSON Web Tokens):