Last active
December 31, 2020 11:13
-
-
Save vjeyaseelan/d3b1cf1d13e448210c92425cf7195fad to your computer and use it in GitHub Desktop.
HTML Assessment1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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() {
</script>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(" ");
}