Chatgpt 3.5 #Designer
Chatgpt 3.5 #Designer
Pop-up boxes in JavaScript are used to display alerts, prompts, or confirmations to the user.
Examples:
Alert Box:
javascript
alert("This is an alert message");
Prompt Box:
javascript
var name = prompt("Please enter your name", "John Doe");
alert("Hello, " + name);
Confirm Box:
javascript
var result = confirm("Are you sure you want to delete?");
if (result) {
// Delete operation
} else {
// Cancel operation
}
Differentiate between Client-Side Scripting and Server-Side Scripting.
Client-Side Scripting: Scripts executed on the client's browser. It is used to enhance the user interface and interactivity of web
pages. Examples include JavaScript.
Server-Side Scripting: Scripts executed on the server before the web page is sent to the client's browser. It is used to generate
dynamic content and interact with databases. Examples include PHP, Python (Django), Ruby (Rails), etc.
What do you mean by event in JavaScript? Give at least two examples of events with their handling.
An event in JavaScript is an action that occurs on a webpage, such as a user clicking a button, hovering over an element, or
submitting a form. Event handling involves writing code to respond to these actions.
Examples:
Click Event:
javascript
document.getElementById("myButton").addEventListener("click", function() {
alert("Button clicked");
});
Mouseover Event:
javascript
document.getElementById("myElement").addEventListener("mouseover", function() {
this.style.color = "red";
});
Explain the Document Object Model. Explain any two-document object with an example.
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<button onclick="alert('Hello, World!')">Click me</button>
</body>
</html>
Program to add numbers using number expressions:
javascript
const num1 = 5;
const num2 = 10;
const sum = num1 + num2;
console.log("Sum:", sum);
Program for string comparison with examples:
javascript
<!DOCTYPE html>
<html>
<head>
<title>Hide Element</title>
<script>
function hideElement() {
document.getElementById("elementToHide").style.display = "none";
}
</script>
</head>
<body>
<div id="elementToHide">
<button onclick="hideElement()">Hide Me</button>
</div>
</body>
</html>
Program of currency filters with decimal examples:
javascript
const options = {
ChatGPT 3.5 #designer
hostname: 'httpbin.org',
port: 80,
path: '/post',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
res.on('end', () => {
console.log("Response:", data);
});
});
req.write(postData);
req.end();
Program to bind data to input controls:
html
<!DOCTYPE html>
<html>
<head>
<title>Bind Data</title>
<script>
window.onload = function() {
const data = "Hello, World!";
document.getElementById("inputField").value = data;
}
</script>
</head>
<body>
<input type="text" id="inputField">
</body>
</html>
Form validations program on submit event:
html
<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<script>
function validateForm() {
const name = document.getElementById("name").value;
if (name === "") {
alert("Name must be filled out");
return false;
}
}
</script>
</head>
<body>
<form onsubmit="return validateForm()">
Name: <input type="text" id="name"><br>
<input type="submit" value="Submit">
</form>
</body>
// Connection URL
const url = 'mongodb://localhost:27017';
// Database Name
const dbName = 'mydatabase';
const db = client.db(dbName);
// Close connection
client.close();
});
});
Insert a record in "employees" collection:
For this, we can reuse the same code snippet from the previous example.
Write an AngularJS program to check if two objects or two values are equivalent or not:
html
<!DOCTYPE html>
<html>
<head>
<title>AngularJS Object Equality Check</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
var obj1 = {a: 1, b: 2};
var obj2 = {a: 1, b: 2};
$scope.areEqual = angular.equals(obj1, obj2);
});
</script>
const fs = require('fs');
// Create a file
fs.writeFile('example.txt', 'Hello, World!', function(err) {
if (err) throw err;
function isArmstrong(number) {
const numString = number.toString();
const numDigits = numString.length;
let sum = 0;
<!DOCTYPE html>
<html>
<head>
<title>Welcome to India</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<h1>{{message}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.message = "Welcome to India";
});
</script>
</body>
</html>