How to write a Javascript application using code below that reads names separated by spaces and for output lists the names with the first letter of every name converted to uppercase and the rest to lower case making sure to sort the output list.
<!DOCTYPE>
<html>
<head>
<title>EXAM01_02</title>
<style type="text/css">
form{color:black;background-color:lightgray;border:6px solid
black;border-width:4px;width:450px;margin:1px;padding:1px;}
#ans1,#ans2,#ans3,#names{background-color:white;border:4px solid
black;}
input[type="button"]{color:black;background-color:red;border:4px
solid black;}
input[type="text"]{margin:2px;}
div.title{color:white;background-color:black;float: left; width:
450px; text-align:center;}
</style>
</head>
<body>
<form>
<div
class="title"><label>EXAM01_02</label></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>Enter Name
List:</label></div><div
style="float:left;"><input type="text" id="names"
/></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>Answer:</label></div><div
style="float:left;"><input type="text" id="ans1"
/></div>
<p style="clear:both;" />
<div style="text-align:center;">
<input type="button" value="Enter" />
<input type="button" value="Clear"
/>
</div>
</form>
</body>
</html>
Answer:
Code:
<!DOCTYPE>
<html>
<head>
<title>EXAM01_02</title>
<style type="text/css">
form{color:black;background-color:lightgray;border:6px solid
black;border-width:4px;width:450px;margin:1px;padding:1px;}
#ans1,#ans2,#ans3,#names{background-color:white;border:4px solid
black;}
input[type="button"]{color:black;background-color:red;border:4px
solid black;}
input[type="text"]{margin:2px;}
div.title{color:white;background-color:black;float: left; width:
450px; text-align:center;}
</style>
</head>
<body>
<form>
<div
class="title"><label>EXAM01_02</label></div>
<p style="clear:both;" />
<div style="float:left;width:150px;"><label>Enter Name
List:</label></div><div
style="float:left;"><input type="text" id="names"
/></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>Answer:</label></div><div
style="float:left;"><input type="text" id="ans1"
/></div>
<p style="clear:both;" />
<div style="text-align:center;">
<input type="button" value="Enter" onclick="fun();" />
<input type="button" value="Clear" />
</div>
<script type="text/javascript">
function fun()
{
var m=document.getElementById("names").value;
var result=m.toLowerCase().split(" ");
for (var i=0;i<result.length;i++)
{
result[i]=result[i].charAt(0).toUpperCase()+result[i].substring(1);
}
result.sort();
res1=result.join(" ");
document.getElementById("ans1").value=res1;
}
</script>
</form>
</body>
</html>
Output:
Get Answers For Free
Most questions answered within 1 hours.