Skip to content

Instantly share code, notes, and snippets.

@vjeyaseelan
Last active December 31, 2020 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjeyaseelan/d3b1cf1d13e448210c92425cf7195fad to your computer and use it in GitHub Desktop.
Save vjeyaseelan/d3b1cf1d13e448210c92425cf7195fad to your computer and use it in GitHub Desktop.
HTML Assessment1
<html>
<head>
<script>
function countWord(){
wordCount=document.getElementById('_userWord').value.trim().split(/\s+/).length;
document.getElementById('_result').value=wordCount;
}
function uniqueWords() {
var words = [];
var counts = [];
inputs=document.getElementById('_userWord').value.trim().split(/\s+/);
for (var i = 0; i < inputs.length; i++) {
var isExist = false;
for (var j = 0; j < words.length; j++) {
if (inputs[i] == words[j]) {
isExist = true;
counts[i] = counts[i] + 1;
}
}
if (!isExist) {
words.push(inputs[i]);
counts.push(1);
}
isExist = false;
}
document.getElementById('_result').value=words.join(" ");
}
function titleCase() {
var sentence = document.getElementById('_userWord').value.trim().toLowerCase().split(/\s+/);
for(var i = 0; i< sentence.length; i++){
sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1);
}
document.getElementById('_result').value=sentence.join(" ");
}
</script>
</head>
<body>
<table width="30%" border="0">
<tr>
<td align="center" colspan="3">
<textarea name="user_word" style="width: 600px; height: 150px;" id="_userWord" value="word1 word2 word3 word4 word1 word5"/>word1 word2 word3 word4 word1 word5
</textarea>
</td>
</tr>
<tr>
<td align="center" colspan="3"/>
</tr>
<tr>
<td align="center"><input type="button" value="Word count" onClick="javascript:countWord()"/> </td>
<td align="center"><input type="button" value="Unique words" onClick="javascript:uniqueWords()"/> </td>
<td align="center"><input type="button" value="Title case"onClick="javascript:titleCase()"/> </td>
</tr>
<tr>
<td colspan="3">
<textarea name="user_word" style="width: 600px; height: 150px;" id="_result"></textarea>
</td>
</tr>
</table>
</body>
</html>
@vjeyaseelan
Copy link
Author

<script> function countWord(){ wordCount=document.getElementById('_userWord').value.trim().split(/\s+/).length; document.getElementById('_result').value=wordCount; }

function uniqueWords() {
var words = [];
var counts = [];
inputs=document.getElementById('_userWord').value.trim().split(/\s+/);
for (var i = 0; i < inputs.length; i++) {
var isExist = false;
for (var j = 0; j < words.length; j++) {
if (inputs[i] == words[j]) {
isExist = true;
counts[i] = counts[i] + 1;
}
}
if (!isExist) {
words.push(inputs[i]);
counts.push(1);
}
isExist = false;
}

document.getElementById('_result').value=words.join(" ");
}

function titleCase() {
var sentence = document.getElementById('_userWord').value.trim().toLowerCase().split(/\s+/);
for(var i = 0; i< sentence.length; i++){
sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1);
}
document.getElementById('_result').value=sentence.join(" ");
}

</script>
<textarea name="user_word" style="width: 600px; height: 150px;" id="_userWord" value="word1 word2 word3 word4 word1 word5"/>word1 word2 word3 word4 word1 word5 </textarea>
<textarea name="user_word" style="width: 600px; height: 150px;" id="_result"></textarea>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment