html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Electric Flux Calculator for Sphere</h1>
<p>Electric Field:</p>
<input id='ef'>
<p>radius:</p>
<input id='radius'>
<p>Angle</p>
<input id='angle'><br><br>
<button id='submit' onclick='final()'>Submit</button>
<div id='result'></div>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
body
{
}
Enter to Rename, Shift+Enter to Preview
js
js
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
let inputs = (id) => parseInt(document.getElementById(id).value)
let result = document.getElementById('result')
let formula = () => {
let ef = inputs('ef')
let radius = inputs('radius')
let angle = inputs('angle')
let r = sphereArea(radius)
let angle_radians = angle * (Math.PI / 180) // Convert angle from degrees to radians
let flux = ef * r * Math.cos(angle_radians)
return flux
}
let sphereArea = (radius) =>{
area = 4* Math.PI * (radius**2) // Use the correct formula for the surface area of a sphere
return area
}
let final = () =>{
let flux = formula()
result.innerText = `Electric Flux is ${flux}`
}
/* Why this deosnt work?
let inputs = (id) => parseInt(document.getElementById(id).value)
let [ef,radius,angle] = ['ef','radius','angle'].map(inputs)
let result = document.getElementById('result')
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run