Modern Application Development II, Quiz 2
Consider the following Vue application with markup “index.html” and javascript file “app.js”. index.html:
app.js:
const a = new Vue({ el : '#app', data : { data : "", refreshes : 0, }, methods: {
do_something() { if (isNaN(this.refreshes)) this.refreshes = 0; if (this.data.length % 2) { sessionStorage.data = "prefix" + this.data; sessionStorage.refreshes = this.refreshes * 2 + 1; } else { sessionStorage.data = this.data + "suffix"; sessionStorage.refreshes = this.refreshes * 2 - 1; } } }, mounted : function () { if (sessionStorage.data) { this.data = "suffix" + sessionStorage.data; this.refreshes = Number(sessionStorage.refreshes) % 3 - 1; }
else { this.data = sessionStorage.data + "prefix"; this.refreshes = Number(sessionStorage.refreshes) % 3 + 1; }
sessionStorage.data = this.data; sessionStorage.refreshes = this.refreshes; }})Say you open the file “index.html” in the browser, and enter the text “iitm” in the text box shown (after removing the existing text from the input box), and click on the button with the text “Click Me”. After that, you refresh the page twice. What will be the text shown in the text input box, and the value of the “refreshes” placeholder, respectively?
Consider the following Vue application with markup “index.html” and javascript file “app.js”. index.html: Figure from the original question paper app.js: const a = new Vue({ el : '#app', data : { data : "", refreshes : 0, }, methods: { do_something() { if (isNaN(this.refreshes)) this.refreshes = 0; if (this.data.length % 2) { sessionStorage.data = "prefix" + this.data; sessionStorage.refreshes = this.refreshes * 2 + 1; } else { sessionStorage.data = this.data + "suffix"; sessionStorage.refreshes = this.refreshes * 2 - 1; } } }, mounted : function () { if (sessionStorage.data) { this.data = "suffix" + sessionStorage.data; this.refreshes = Number(sessionStorage.refreshes) % 3 - 1; } else { this.data = sessionStorage.data + "prefix"; this.refreshes = Number(sessionStorage.refreshes) % 3 + 1; } sessionStorage.data = this.data; sessionStorage.refreshes = this.refreshes; } }) Say you open the file “index.html” in the browser, and enter the text “iitm” in the text box shown (after removing the existing text from the input box), and click on the button with the text “Click Me”. After that, you refresh the page twice. What will be the text shown in the text input box, and the value of the “refreshes” placeholder, respectively? Suppose you are organizing a ceremony to award the startup companies who have progressed considerably well in the past few years. You have received a lot of registrations. The committee has decided to shortlist the companies based on the following 2 criteria:\ 1\. The company must have a website\ 2\. The company must have a capital of more than 40000\ Fill in the **code1** \& **code2**, which can be used in Vuex Store to update the “awardees” state variable with the objects of those companies who satisfy the above-mentioned criteria. const store = new Vuex.Store({ state : { companies : [ { name : 'sample1', website : 'sample1.com', capital : 50000 }, { name : 'sample2', website : null, capital : 75000 }, { name : 'sample3', website : 'sample3.com', capital : 42000 }, { name : 'sample4', website : 'sample4.com', capital : 38000 }, ], awardees : [] }, mutations : { update_final(state, minimum) { for (company of state.companies) code2 } }, actions : { send_task : function (context) { code1 } } }) Consider the following JavaScript program running in a browser environment. async function FetchFunct(ApiUrl) { const response = await fetch(ApiUrl).catch(() => { throw new Error('Network Error') }) if (response) { if (response.ok) { const data = await response.json().catch(() => { throw new Error('Unexpected Error') }) if (data) { return data } } else { throw new Error(response.statusText) } } } Const url = ‘dummyUrl’ FetchFunct(url) .then((data) => { console.log(data) }) .catch((err) => { console.log(err.message) }) Consider the ‘dummyUrl’ returns the HTML as payload. What will be logged on to the console?