Question: function checkAlliteration ( ) { try { / / Get the value of char & alliter components var char = document.getElementById ( char
function checkAlliteration
try
Get the value of char & alliter components
var char document.getElementByIdcharvalue.toLowerCase;
var sentence document.getElementByIdallitervalue.toLowerCase;
Invoke getCount method to get the number of words
var wordCount getCountsentence;
if wordCount
document.getElementByIdresultinnerHTML "Invalid number of words";
return;
Invoke validateSentence method to check if the sentence is valid
var isValid validateSentencesentence;
if isValid
document.getElementByIdresultinnerHTML "Invalid sentence";
return;
Invoke getScore method to calculate the score
var score getScoresentence char;
document.getElementByIdresultinnerHTML "Your score is score;
catch err
document.getElementByIdresultinnerHTML "Error in checkAlliteration: err;
function getCountstr
try
Calculates the number of words in the string and returns the count
var count ;
var isWord false;
for var i ; i strlength; i
if stri
if isWord
isWord true;
count;
else
isWord false;
return count;
catch err
document.getElementByIdresultinnerHTML "Function getCount: err;
return ;
function validateSentencestr
try
When any word in the string starts with a vowel, return false; else, return true
var vowels new Setaeiou;
var words strtrimsplits;
for var i ; i words.length; i
var word wordsireplaceazAZg;
if wordlength vowels.haswordcharAttoLowerCase
return false;
return true;
catch err
document.getElementByIdresultinnerHTML "Function validateSentence: err;
return false;
function getScorestr char
try
Compare the first letter of every word in the string with the character, calculate and return score
var words strsplits;
var correctWords ;
for var i ; i words.length; i
var word wordsireplaceazAZg;
if wordlength && word.charAttoLowerCase char.toLowerCase
correctWords;
var score ;
if correctWords
score correctWords : correctWords ;
return score;
catch err
document.getElementByIdresultinnerHTML "Function getScore: err;
return ;
Please check the logic for getScore method for a valid sentence with incorret word
Check the logic of the validateSentence method for a valid sentence
How to fix it
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
