Modern Application Development II, Quiz 2
Consider the below javascript program.
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 below javascript program. 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: 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: <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: <body> <div id="app"></div> </body> app.js: 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' }, ], } }, 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/#/”?