-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
27 lines (24 loc) · 814 Bytes
/
main.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
$(document).ready(function() {
// Function to add a new input field
$('#add-sensor').click(function() {
$('#sensor-inputs').append('<input type="number" class="form-control mt-3 sensor-value" placeholder="Enter sensor value">');
});
// Function to calculate the average value
$('#calculate-average').click(function() {
let total = 0;
let count = 0;
$('.sensor-value').each(function() {
let value = parseFloat($(this).val());
if (!isNaN(value)) {
total += value;
count++;
}
});
if (count > 0) {
let average = total / count;
$('#average-value').text(average.toFixed(2));
} else {
$('#average-value').text('0');
}
});
});