Assignment 2 Web
Assignment 2 Web
ASSIGNMENT 2 23BIT0351
1.) A parking garage charges a $2.00 minimum fee to park for up to three hours. The
garage charges an additional $0.50 per hour for each hour or part thereof above three
hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car
parks for longer than 24 hours at a time. Write a script that calculates and displays the
parking charges for each customer who parked a car in this garage yesterday. You
should input from the user the hours parked for each customer. The program should
display the charge for the current customer and should calculate and display the
running total of yesterday's receipts. The program should use the function calculate
Charges to determine the charge for each customer. Use a prompt dialog to obtain input
from the user.
CODE:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function calculatecharges(hours) {
if (hours <= 3) {
return 2.00;
} else {
while (true) {
break;
continue;
total += charge;
parking_data();
</script>
</body>
</html>
Input 1:
Input 2:
Input 3:
Input 4:
Input 5:
b) The width of the first division is 100%. The second division and third division lay
side by side.
c) The second division has an image slider and the third division has a color picker and
two list boxes having font family and size and a button. When a button is clicked the
background color, font, and font size should change for a whole page. Use JavaScript to
implement the above.
CODE:
<!DOCTYPE html>
<html>
<head>
<title>Three Divisions</title>
<style>
body {
font-family: sans-serif;
#div1 {
width: 100%;
text-align: right;
padding: 10px;
#div2 {
width: 50%;
float: left;
padding: 10px;
#div3 {
width: 50%;
float: right;
padding: 10px;
margin-bottom:50px;
.clearfix::after {
content: "";
display: table;
clear: both;
#imageSlider img {
max-width: 100%;
height: auto;
</style>
</head>
<body>
<div id="div1">
<span id="clock"></span>
</div>
<div id="imageSlider">
</div>
</div>
<div id="div3">
<select id="fontFamily">
<option value="Arial">Arial</option>
<option value="Verdana">Verdana</option>
</select>
<select id="fontSize">
<option value="12px">12px</option>
<option value="14px">14px</option>
<option value="16px">16px</option>
<option value="18px">18px</option>
</select>
</div>
</div>
<script>
function updateClock() {
setInterval(updateClock, 1000);
updateClock();
var currentImage = 0;
setInterval(() => {
images[currentImage].style.display = "none";
images[currentImage].style.display = "block";
}, 2000);
images[0].style.display = "block";
images[i].style.display = "none";
function applyStyles() {
document.body.style.backgroundColor =
document.getElementById("colorPicker").value;
document.body.style.fontFamily = document.getElementById("fontFamily").value;
document.body.style.fontSize = document.getElementById("fontSize").value;
</script>
</body>
</html>
3.) Write the JavaScript code to add behavior to the following page for manipulating
strings.
a) The page UI allows the user to type a phrase into a text box. The user can click the
"Go!" button to display the words in that phrase in reverse order. Each word in the
phrase should be inserted as a span with a class of word, inside a div with the id of
words. Every other word (the first, third, fifth, etc.) should also be underlined
b) The user can optionally specify a "filter" text by typing into a text box with the id of
the filter. If a non-blank filter is specified, you should exclude any words from the
phrase that contains that filter text, case-insensitively. For example, if the filter text is
"abc", exclude any words containing abc, ABC, aBc, etc.
c) If any words are excluded, under the list of words you should modify the div with an
id of count to display the text of the form, "5 word(s) filtered out". The code should
work for multiple clicks of the button. On each click, it should clear any previous
information you injected. You may assume that words in the phrase are separated by
single spaces.
d) These screenshots show the initial state, and after phrases have been typed and "Go!"
is clicked.
CODE:
<!DOCTYPE html>
<html>
<head>
<title>String Manipulation</title>
<style>
.word {
margin-right: 10px;
border:dotted red;
color:red;
.word.underlined {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Sentence Reverser!</h1>
<button onclick="reverseWords()">Go!</button><br><br>
<div id="words"></div>
<div id="count"></div>
<script>
function reverseWords() {
wordsDiv.innerHTML = "";
countDiv.innerHTML = "";
if (phrase == "")
return;
var filteredCount = 0;
filteredCount++;
continue;
reversedWords.unshift(word);
wordSpan.className = "word";
if (i % 2 === 0) {
wordSpan.classList.add("underlined");
wordSpan.textContent = reversedWords[i];
wordsDiv.appendChild(wordSpan);
if (filteredCount > 0) {
</script>
</body>
</html>