F3 Mock Interview
F3 Mock Interview
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Product List</title>
</head>
<style>
ul {
list-style: none;
padding: 0;
}
li {
margin: 20px 0;
border: 1px solid #ccc;
padding: 20px;
}
h2 {
margin: 0;
}
p {
margin: 10px 0;
}
span {
font-weight: bold;
}
</style>
<body>
<h1>Product List</h1>
<ul id="product-list"></ul>
<script>
fetch('https://dummyjson.com/products')
.then(response => response.json())
.then(data => {
const productList = document.getElementById('product-list');
data.products.forEach(product => {
const li = document.createElement('li');
li.textContent = `${product.title} -
${product.price}-${product.description}`;
productList.appendChild(li);
});
console.log(data)
})
.catch(error => console.error(error));
</script>
</body>
</html>
2. Create a function which returns a promise and returns a random number after
2500 milliseconds.Playground:
https://githubbox.com/acciojob/frontend3_mock_consoleCreate a function
which returns a promise and returns a random number after 2500
milliseconds.Playground:
https://githubbox.com/acciojob/frontend3_mock_console
<body>
<h2 >Random Number:<span id="random-number"></span></h2>
<script>
//function to get random number
function getRandomNumber(){
return new Promise((resolve)=>{
setTimeout(()=>{
const randomNumber= Math.floor(Math.random()*100);
resolve(randomNumber);
},2500);
})
}
//function to display the number
async function displayRandomNumber(){
const randomNumber= await getRandomNumber();
document.getElementById("random-number").innerHTML=
randomNumber;
displayRandomNumber();
</script>
Theory Questions:
1. Explain Merge sort Algorithm
2. What are async functions in JS
3. Async await
4. Promise and Promise chaining
5. Advantages and limitations of React
// function caesarCipher
function caesarCipher( str,shift){
}
console.log(caesarCipher("shital",3));
</script>
2. Create a function called **`delayLog`** that takes two arguments: a string to log
and a number representing the delay in milliseconds. The function should log the
string to the console after the specified delay. For example, calling
**`delayLog('Hello, world!', 2000)`** should log "Hello, world!" to the console after
a 2-second delay.Playground:
https://githubbox.com/acciojob/frontend3_mock_console
<script>
function delayLog(str, delay) {
setTimeout(function () {
console.log(str);
}, delay);
}
delayLog("Hello, world!", 2000);
</script>
3. Create a Calculator: Build a calculator using JavaScript that can perform basic
arithmetic operations such as addition, subtraction, multiplication, and division.
Take 2 numbers as inputs and 4 buttons (+,-,*,/) show the result immediately in a
p tag.UI Reference:
https://storage.googleapis.com/acciojob-open-file-collections/ezgif.com-video-t
o-gif_(8).gifPlayground: https://githubbox.com/saksham-accio?tab=repositories
https://codesandbox.io/p/github/saksham-accio/Frontend3_mock_Calculator
<!DOCTYPE html>
<html>
<head>
<title>Basic Calculator</title>
<script>
function calculate() {
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var operator = document.getElementById("operator").value;
var result;
document.getElementById("result").value = result;
}
</script>
</head>
<body>
<h1>Basic Calculator</h1>
<label for="num1">Number 1:</label>
<input type="number" id="num1"><br><br>
<label for="num2">Number 2:</label>
<input type="number" id="num2"><br><br>
<label for="operator">Operator:</label>
<select id="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select><br><br>
<button onclick="calculate()">Calculate</button><br><br>
<label for="result">Result:</label>
<input type="number" id="result" disabled>
</body>
</html>
4. https://codesandbox.io/p/github/saksham-accio/Frontend3_mock_todolist/main
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>To-Do List</title>
<style>
/* some basic styling for the app */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
#app {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
h1 {
font-size: 36px;
margin-bottom: 20px;
}
label {
display: block;
font-size: 18px;
margin-bottom: 5px;
}
input[type="text"],
textarea {
display: block;
width: 100%;
padding: 10px;
font-size: 18px;
margin-bottom: 20px;
border: 1px solid #ccc;
}
button {
display: block;
background-color: #007bff;
color: #fff;
border: none;
padding: 10px 20px;
font-size: 18px;
cursor: pointer;
}
button:hover {
background-color: #0069d9;
}
ul {
list-style: none;
padding: 0;
margin: 0;
margin-top: 2rem;
}
li {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
.task-title {
font-size: 24px;
margin-bottom: 10px;
}
.task-desc {
font-size: 18px;
}
.task-actions {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
</style>
</head>
<body>
<div id="app">
<h1>To-Do List</h1>
<form id="add-task-form">
<label for="task-title">Task Title:</label>
<input type="text" id="task-title" name="task-title" required />
<label for="task-desc">Task Description:</label>
<textarea id="task-desc" name="task-desc" rows="4"
required></textarea>
<button type="submit">Add Task</button>
</form>
<ul id="task-list"></ul>
</div>
<script>
const addTaskForm = document.getElementById("add-task-form");
const taskList = document.getElementById("task-list");
let tasks = [];
updateTaskList();
}
function updateTaskList() {
taskList.innerHTML = "";
tasks.forEach((task, index) => {
const taskElement = document.createElement("li");
taskElement.innerHTML = `
<div class="task-title">${task.title}</div>
<div class="task-desc">${task.desc}</div>
<div class="task-actions">
<button onclick="removeTask(${index})">Remove</button>
</div>
`;
taskList.appendChild(taskElement);
});
}
Theory Questions :
1. Constructors in javascript
2. Callback and callback hell
3. Status codes in https and their class - HTTP response status codes
4. What is React and its Important features
2. Create a function which returns a promise and returns a random number after
2500 milliseconds.
<body>
<h2 >Random Number:<span id="random-number"></span></h2>
<script>
//function to get random number
function getRandomNumber(){
return new Promise((resolve)=>{
setTimeout(()=>{
const randomNumber= Math.floor(Math.random()*100);
resolve(randomNumber);
},2500);
})
}
//function to display the number
async function displayRandomNumber(){
const randomNumber= await getRandomNumber();
document.getElementById("random-number").innerHTML=
randomNumber;
displayRandomNumber();
</script>
3. Create an input field and take the name of the user through that input field and
have a submit button. Use cookies to store the name. Whenever the page is
reloaded, write a message saying “Hi There - ${name}” where name is fetched
from the cookie you savedUI
<body>
<form>
<label for="name">Enter Your Name</label>
<input type="text" id="name" />
<button type="submit">submit</button>
</form>
<div id="message"></div>
<script>
function setCookies() {
const name = document.getElementById("name").value;
console.log(name);
document.cookie =
"name = " +
encodeURIComponent(name) +" ; expires = Thu,31 Dec 2023
23:59:59 GMT";
document.getElementById("message").textContent = "Hii
there," + name;
}
document
.querySelector("form")
.addEventListener("submit", function (event) {
event.preventDefault();
setCookies();
});
</script>
</body>
Theory Questions :
1. What is web storage
2. Difference between local storage and session storage
3. Promise chaining with code example
4. Advantages and limitations of react
5. Class Inheritance in JS
6. Predict the output :
<script>
function Person() {}
Person.prototype.sayHi = function () {
console.log("hi!");
};
let rahul = new Person();
Person.prototype.sayHi = function () {
console.log("Greetings!");
};
rahul.sayHi();
</script>
Interviewer : Anshika SDE- Microsoft
Coding Questions :
1. Write a function called caesarCipher that takes in two arguments: a string to
encode and a number representing the shift. The function should shift each letter
of the string by the shift amount to the right in the alphabet. For example, if the
shift is 3, then "a" becomes "d", "b" becomes "e", "c" becomes "f", and so
on.Playground: https://githubbox.com/acciojob/frontend3_mock_console
<script>
// function caesarCipher
function caesarCipher( str,shift){
for(var i=0;i<chars.length;i++){
var charCode = chars[i].charCodeAt(0);//
}
console.log(caesarCipher("shital",3));
</script>
2 . Create a class called **`Animal`** with the following properties and methods:
- **`name`**: a string representing the name of the animal
- **`age`**: a number representing the age of the animal
- **`sound`**: a string representing the sound that the animal makes
- **`makeSound()`**: a method that logs the animal's sound to the console
- Create a subclass called **`Cat`** that inherits from **`Animal`**, and add the
following properties and methods:
- **`breed`**: a string representing the breed -->
- **`meow()`**: a method that logs "meow" to the console
<script>
class Animal {
constructor(name, age, sound) {
this.name = name;
this.age = age;
this.sound = sound;
}
makeSound() {
console.log(this.sound);
}
}
meow() {
console.log("meow");
}
}
const myCat = new Cat("jimmy", 3, "cat", "cat");
console.log(myCat.name);
console.log(myCat.age);
console.log(myCat.sound);
console.log(myCat.breed);
myCat.makeSound();
myCat.meow();
</script>
Theory Questions :
1. callback
2. callback hell with code example & solutions
3. What is heap memory
4. Constructors with code example
5. What is React and Its Features
6. Predict output :
function introduceAccio() {
return 'Hi, I am AccioJob!';
}
console.log(introduceAccio.prototype);
console.log(completeTest.prototype);
}