-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFeedback.html
179 lines (153 loc) · 5.45 KB
/
Feedback.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rating Calculation</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #333;
color: white;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h2 {
color: #4CAF50;
}
form {
margin-top: 20px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="number"] {
width: 100%;
padding: 8px;
margin-bottom: 15px;
box-sizing: border-box;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
color: #4CAF50;
}
#userRating {
margin-top: 20px;
}
.navbar {
background-color: #4CAF50;
/* Green background color for the navbar */
padding: 10px 0;
}
.container1 {
display: flex;
justify-content: space-between;
align-items: center;
width: 80%;
margin: 20px auto;
/* Full viewport height */
}
.logo {
color: white;
font-size: 24px;
font-weight: bold;
}
.nav-links {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
.nav-links li {
margin-right: 20px;
}
.nav-links a {
text-decoration: none;
color: white;
font-weight: bold;
}
</style>
</head>
<body>
<nav class="navbar">
<div class="container1">
<div class="logo">Hunger Help</div>
<ul class="nav-links">
<li><a href="WhatToDonate.html">Home</a></li>
<li><a href="AboutUs.html">About</a></li>
<li><a href="Contact.html">Contact Us</a></li>
<li><a href="Feedback.html">Rating&Feedback</a></li>
</ul>
</div>
</nav>
<!-- Container for Rating Calculation -->
<div class="container">
<div id="result"></div>
<h2>Give Your Own Rating</h2>
<form id="ratingForm" onsubmit="calculateRating(); return false;">
<label for="ratings">Enter your ratings (1-5):</label>
<input type="number" id="ratings" name="ratings" min="1" max="5" required>
<input type="submit" value="Submit Rating">
</form>
<div id="userRating"></div>
</div>
<script>
// Initialize average rating from localStorage or use a default value
var currentRating = parseFloat(localStorage.getItem("averageRating")) || 4.0;
// Display the initial average rating on page load
document.getElementById("result").innerHTML = "Average Rating: " + currentRating.toFixed(2);
function calculateRating() {
// Get the entered ratings value
var ratingsInput = document.getElementById("ratings");
var ratingsValue = parseFloat(ratingsInput.value);
// Check if the entered value is within the valid range (1-5)
if (ratingsValue >= 1 && ratingsValue <= 5) {
// Calculate and display the result
var resultContainer = document.getElementById("result");
var averageRating = calculateAverageRating(ratingsValue);
resultContainer.innerHTML = "Average Rating: " + averageRating.toFixed(2);
// Display user's rating
var userRatingContainer = document.getElementById("userRating");
userRatingContainer.innerHTML = "Your Rating: " + ratingsValue;
// Store the updated average rating in localStorage
localStorage.setItem("averageRating", averageRating);
} else {
// Display an error message for invalid input
alert("Please enter a valid rating between 1 and 5.");
}
// Reset the form
document.getElementById("ratingForm").reset();
}
function calculateAverageRating(newRating) {
// You can implement more sophisticated logic for calculating average ratings
// For simplicity, let's assume a simple average here
var totalRatings = 100; // Assume the total number of ratings
// Calculate the new average rating
var newAverageRating = ((currentRating * totalRatings) + newRating) / (totalRatings + 1);
// Update the current average rating
currentRating = newAverageRating;
return newAverageRating;
}
</script>
</body>
</html>