WDF Unit 1 and 2 DN Exercises
WDF Unit 1 and 2 DN Exercises
Create a JS Object for Bank Account (w attributes like à customer name, account type,
balance, data of creation, bank name, branch name, pan card number). Using JS Object
keyword, try to perform following activities ➢ List down all the entries of the bank object ➢
Check the existence of a key ➢ If key found, get the value for the key
const bankAccount = {
accountType: "Savings",
balance: 15000.75,
dateOfCreation: "2021-05-15",
panCardNumber: "ABCDE1234F"
};
if (bankAccount.hasOwnProperty(key)) {
console.log(`${key}: ${bankAccount[key]}`);
} else {
Spread Operator ➢ Merge Customer and Account Arrays ➢ Update the Customer Object
with the new values ➢ Develop a function that takes a Spread Argument and calculates total
balance
const customers = [
];
const accounts = [
];
console.log(mergedData);
console.log(mergedData);
// 3. Develop a function that takes a Spread Argument and calculates total balance
function calculateTotalBalance(...balances) {
);
console.log(`Total Balance: ${totalBalance}`);
UNIT 2
Create a list of Bank Objects (same kind of object you used in above lab, but in an array
format) ➢ Display the banks where balance is greater than 200 ➢ deduct 10% of the Bank
account balance, as part of monthly service fees ➢ Display the banks where balance is
greater than 200 and branch code is “Chennai” ➢ Add a new Bank to the given array ➢
Delete a bank from the array (use splice operator) ➢ Calculate the total balance of all bank
accounts
const bankAccounts = [
accountType: "Savings",
balance: 2500.75,
dateOfCreation: "2021-05-15",
branchName: "Chennai",
panCardNumber: "ABCDE1234F"
},
accountType: "Checking",
balance: 150.50,
dateOfCreation: "2020-03-10",
branchName: "Mumbai",
panCardNumber: "FGHIJ5678K"
},
accountType: "Savings",
balance: 3000.00,
dateOfCreation: "2019-07-20",
branchName: "Chennai",
panCardNumber: "LMNOP9012Q"
},
accountType: "Current",
balance: 500.00,
dateOfCreation: "2022-01-05",
branchName: "Delhi",
panCardNumber: "RSTUV3456W"
];
bankAccounts.forEach(account => {
console.log(account);
}
});
// 2. Deduct 10% of the Bank account balance as part of monthly service fees
bankAccounts.forEach(account => {
});
// 3. Display the banks where balance is greater than 200 and branch code is “Chennai”
console.log("\nBanks with balance greater than 200 and branch code 'Chennai':");
bankAccounts.forEach(account => {
console.log(account);
});
const newBankAccount = {
accountType: "Savings",
balance: 1200.00,
dateOfCreation: "2023-02-10",
branchName: "Chennai",
panCardNumber: "XYZAB6789C"
};
bankAccounts.push(newBankAccount);
console.log(deletedAccount[0]);
Develop a Scientific calculator that does following operations ➢ Rounded Value ➢ Area of
Circle ➢ Calculating of Sin, Cos and Tan functions ➢ Permiter of a Rectangle ➢ Employ
Arrow functions ➢ Employ HOC
};
// Operations
// Trigonometric functions
// Example usage
3) Develop a Tic Tac Toe game using ES6 JS. ❑Building a simple Tic Tac Toe game with
JavaScript is another excellent project idea you can finish in a single day. ❑You will create a
3×3 grid where two players will take turns marking the grid with cross and circle symbols.
The first player to get three marks in a horizontal, vertical, or diagonal row wins the game.
❑Although the game seems simple, you need to figure out how to create the logic that
follows the game rules in JavaScript. ❑Hence, before you start writing any code, break down
the flow of the game into logical steps first. ❑For a simple game like Tic Tac Toe, I find it
helpful to draw a small flow chart to visualize the different outcomes of the game. When I
can see the flow on paper, it’s easier to start writing actual code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.cell { width: 100px; height: 100px; display: flex; align-items: center; justify-content:
center; font-size: 24px; border: 1px solid #000; cursor: pointer; }
</style>
</head>
<body>
<script>
class TicTacToe {
constructor() {
this.board = Array(9).fill(null);
this.currentPlayer = 'X';
this.isGameActive = true;
this.init();
init() {
this.renderBoard();
this.updateMessage();
renderBoard() {
boardElement.innerHTML = '';
cellElement.classList.add('cell');
cellElement.textContent = cell;
cellElement.addEventListener('click', () => this.handleCellClick(index));
boardElement.appendChild(cellElement);
});
handleCellClick(index) {
this.board[index] = this.currentPlayer;
if (this.checkWin()) {
this.updateMessage(`${this.currentPlayer} wins!`);
this.isGameActive = false;
this.updateMessage("It's a draw!");
this.isGameActive = false;
} else {
this.updateMessage();
this.renderBoard();
checkWin() {
const winPatterns = [
];
return winPatterns.some(pattern => {
});
document.getElementById('message').textContent = message;
resetGame() {
Develop a JavaScript palindrome checker. A palindrome is a phrase or a word that reads the
same backwards and forwards. Building a simple palindrome checker is great practice for
working with strings and manipulating them with JavaScript. Plus, checking for palindromes
can be a lot of fun!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Palindrome Checker</title>
<style>
</style>
</head>
<body>
<div class="container">
<h1>Palindrome Checker</h1>
</div>
<script>
document.getElementById('checkButton').addEventListener('click', function() {
document.getElementById('result').textContent = result ?
`"${inputString}" is a palindrome!` :
});
function isPalindrome(str) {
</script>
</body>
</html>