Midterm Laboratory Exercise: Group Leader (LN, FN MI.) : Score: Group Members (LN, FN MI.) : in Alphabetical Order
Midterm Laboratory Exercise: Group Leader (LN, FN MI.) : Score: Group Members (LN, FN MI.) : in Alphabetical Order
3 Cirilo, Zedric
MI.): In alphabetical Order
4 Dimaculangan, Gian
5 Efergan, Iris B.
7 Mirabel, Shannyn M.
Section: 2IT - E Instructor: Prof. Janus Raymond C. Tan Sem./ 2nd/ 22-23
A.Y.
EFFICIENCY The code is huge The code is brute The code is fairly The code is 30
and force and efficient without extremely efficient
appears to be unnecessarily long. sacrificing without sacrificing
patched readability and readability and
together. understanding. understanding.
CORRECTNESS The program The program works The program works The program 30
does not run. but may encounter but have minor works and
run-time errors or issues in some meets all of the
incorrect output in specifications. specifications.
some scenarios.
INSTRUCTION:
Create simple web application that will allow a user to enter a String in a text field and will generate the
following output in a tag with id = “pOutput” using HTML DOM:
1) Uppercase First Character of Every Word Function: UFCWord(str) – returns a new string which
changes the first character of every word to a capital letter.
2) Uppercase Last Character of Every Word Function: ULCWord(str) – returns a new string which
changes the last character of every word to a capital letter.
3) Reverse the String Function: revString(str) – returns a new string which contains the reversed
sequence of characters within the String.
Sample Test Cases:
Assume that the user will enter a single SPACE character between words. THE CHALLENGE IS, YOU ARE
NOT ALLOWED TO USE ANY BUILT-IN JAVASCRIPT STRING FUNCTIONS TO COMPLETE THE
REQUIREMENTS. Formulate your own logic to answer the problem.
Each operation will be assigned with individual buttons for execution. Include a CLEAR button that will
clear all the contents of the fields and to allow the user to repeat the program execution. All operations
given in the bullets will be equivalent to JavaScript functions (you can use whatever type of function will
you use, either function declaration, function expression or arrow function). Use an external JavaScript file
to separate the HTML from JavaScript code. You can design your web application depending on your
choice.
IMPORTANT NOTE:
1) Use only the topics we discussed as ways to answer this problem otherwise your score will be considered
ZERO.
2) If in case there will be possible answers from the internet, make sure not to copy the code and make
your own self-made solutions. Failure to do so will mean a score of ZERO.
3) Make sure to refresh the page of the LMS before submission so that possible errors will not be
encountered.
4) All members should submit his/ her own attachment.
5) Late submissions will not be accepted.
6) No excuses related to internet connection or technical problems will be
considered.
PROGRAM CODE:
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML Test</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>String Manipulation</h1>
<input type="text" id="inputString" placeholder="Enter a string">
<div>
<button id="btnUFCWord">Uppercase</button>
<button id="btnULCWord">Lowercase</button>
<button id="btnRevString">Reverse String</button>
<button id="btnClear">Clear</button>
</div>
<p id="pOutput"></p>
<script src="script.js"></script>
</body>
</html>
CSS
body {
background-color: #899499;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
h1 {
text-align: center;
color: white; /* Make the text color white to contrast with the background */
}
input[type="text"] {
display: block;
margin: 0 auto;
padding: 10px;
width: 50%;
}
button {
background-color: #D3D3D3;
border: 2px solid white; /* Add a white border to make the button visible against the background */
color: black; /* Change the text color to black to contrast with the button background */
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
button:hover {
background-color: #71797E;
}
#btnClear {
background-color: #800020;
}
#btnClear:hover {
background-color: #880808;
}
div {
text-align: center;
margin-top: 20px;
}
p{
text-align: center;
font-size: 18px;
margin-top: 20px;
color: white; /* Make the text color white to contrast with the background */
JS
// Reverse a string
function revString(str) {
let result = "";
for (let i = str.length - 1; i >= 0; i--) {
result += str.charAt(i);
}
return result;
}
// Apply the UFCWord function to the input string and display the result
const applyUFCWord = () => {
const inputString = document.getElementById("inputString").value;
const outputString = UFCWord(inputString);
document.getElementById("pOutput").innerHTML = outputString;
}
// Apply the ULCWord function to the input string and display the result
const applyULCWord = () => {
const inputString = document.getElementById("inputString").value;
const outputString = ULCWord(inputString);
document.getElementById("pOutput").innerHTML = outputString;
}
// Apply the revString function to the input string and display the result
const applyRevString = () => {
const inputString = document.getElementById("inputString").value;
const outputString = revString(inputString);
document.getElementById("pOutput").innerHTML = outputString;
}
String Manipulation
Uppercase
When the "Uppercase" button is clicked, the applyUFCWord function is called. This function retrieves
the input string from the HTML input field with the id "inputString". It then applies the UFCWord function to the
input string, which capitalizes the first letter of each word in the string. The resulting output string is then
displayed in the HTML paragraph element with the id "pOutput".
The UFCWord function splits the input string into an array of words using the space character as a delimiter. It
then loops through each word and capitalizes the first letter of each word using the charAt() and substring()
methods. Finally, it joins the array of words back into a string using the space character as a delimiter and
returns the resulting string.
Overall, the "Uppercase" button takes an input string, capitalizes the first letter of each word, and displays the
resulting output string in the HTML paragraph element.
Lowercase
The "Lowercase" button is one of the four buttons on the webpage designed to manipulate strings.
When clicked, it triggers the applyULCWord function, which applies the ULCWord function to the input string.
The ULCWord function capitalizes the last letter of each word in the input string and returns the modified string.
Finally, the modified string is displayed in the output area on the webpage.
Reverse String
The "Reverse String" button triggers the applyRevString() function, which takes the input string from the
text field and passes it to the revString() function. The revString() function then reverses the order of the
characters in the string using a for loop, and returns the reversed string to applyRevString(). Finally,
applyRevString() updates the output area with the reversed string. Therefore, when the "Reverse String" button
is clicked, the string entered in the input field is reversed and displayed in the output area.
Clear
The clear button resets the input field and output area, clearing any text that was entered or displayed.
Attach the PDF file (all members should turn in) as your submission in the assigned task upon
submitting using your LMS Account following the given format above. (your PDF file should begin with
the first page of the given format)