Question 1
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?
suffixiitmsuffix, -2
suffixsuffixiitmsuffix, -2
suffixsuffixiitmsuffix, -3
suffixiitmsuffix, -3
