Experiment List for Front-End Web Development
Experiment List for Front-End Web Development
alert('Welcome to JavaScript!');
console.log('Welcome to JavaScript!');
2. Demonstrate the use of variables: Create variables with let, const, and
var, and display their values.
console.log('Name:', name);
console.log('Age:', age);
console.log('City:', city);
console.log('String:', str);
console.log('Number:', num);
console.log('Boolean:', isActive);
console.log('Addition:', a + b);
console.log('Subtraction:', a - b);
console.log('Multiplication:', a * b);
console.log('Division:', a / b);
let x = 10;
let y = '10';
6. Write a function that takes two numbers and returns their sum:
Implement a simple JavaScript function to calculate the sum of two
numbers
function add(a, b) {
return a + b;
}
let number = 7;
// if-else
if (number > 0) {
console.log('Positive number');
} else {
console.log('Non-positive number');
}
// switch
switch (number) {
case 1:
console.log('One');
break;
case 7:
console.log('Seven');
break;
default:
console.log('Other number');
}
function isEven(num) {
return num % 2 === 0;
}
function testScope() {
let localVar = 'I am local';
console.log(globalVar); // Accessible
console.log(localVar); // Accessible
}
testScope();
console.log(globalVar); // Accessible
// console.log(localVar); // Uncaught ReferenceError: localVar is
not defined
10. Write an arrow function that takes two parameters and returns their
product: Create an arrow function to multiply two numbers
myPromise
.then(result => {
console.log(result);
})
.catch(error => {
console.error(error);
});
13. Handle events in JavaScript: Set up event listeners like click and
hover using addEventListener().
document.getElementById('clickBtn').addEventListener('click', () =>
{
alert('Button clicked!');
});
document.getElementById('colorPicker').addEventListener('input',
(event) => {
document.body.style.backgroundColor = event.target.value;
});
$('#myDiv').text('jQuery is fun!');
$('.myClass').css('color', 'green');
16. Add click event listeners to buttons in jQuery: Change the text
content of elements on button click using jQuery
$('#myButton').on('click', function () {
$('#text').text('You clicked the button!');
});
17. Create simple animations in jQuery: Implement animations like
fade-in and fade-out using jQuery effects.
$('#fadeBtn').on('click', function () {
$('#box').fadeOut();
});
18. Perform AJAX requests using jQuery: Fetch data from a remote API
using $.ajax() in jQuery
$('#fetchData').on('click', function () {
$.ajax({
url: 'https://jsonplaceholder.typicode.com/posts/1',
method: 'GET',
success: function (response) {
$('#data').text(JSON.stringify(response));
},
});
});
19. Toggle the visibility of elements with jQuery: Use jQuery to hide or
show elements based on button clicks.
$('#toggleBtn').on('click', function () {
$('#content').toggle();
});
20. Create a React app using create-react-app: Set up and run your first
React application with create-react-app.
23. Create and use state in a functional React component: Use the
useState hook to manage and update state in a React component.
useEffect(() => {
const interval = setInterval(() => {
console.log('Tick');
}, 1000);
<input
type="text"
value={text}
onChange={(e) => setText(e.target.value)}
/>
<p>You typed: {text}</p>