-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.js
More file actions
39 lines (36 loc) · 1.09 KB
/
demo.js
File metadata and controls
39 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//function to calculate the area of a circle
function calculateArea(radius) {
return Math.PI * Math.pow(radius, 2);
}
//function to validate an email address using regex
function validateEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
//function to fetch data from an API and log the response
async function fetchData(url) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error fetching data:', error);
}
}
//function to convert any currency to INR using a fixed exchange rate function
function convertToINR(amount, currency) {
const exchangeRates = {
USD: 74.85,
EUR: 88.50,
GBP: 103.20,
JPY: 0.68
};
if (Object.hasOwn(exchangeRates, currency)) {
return amount * exchangeRates[currency];
} else {
throw new Error('Unsupported currency');
}
}