Question

Question #4 Write a JavaScript function HideMe() that takes a user specified sentence and hides a certain words by replacing
0 0
Add a comment Improve this question Transcribed image text
Answer #1

<!DOCTYPE html>
<html>
<head>
<style>
#demo {
background-color: LimeGreen;
color: black;
}
</style>
</head>
<body>

<button onclick="HideMe('The deadline is August 4th')">Try it</button>

<p id="demo"></p>

<script>
//javascript function
function HideMe(sentence) {
  
var flag = true;
//if soen287 is NOT found, -1 is returned.
if (sentence.toLowerCase().indexOf('soen287') !=-1)
{
//replacing soen287 with XXXXXXX
sentence = sentence.replace("soen287", "XXXXXXX");
flag = false;
}
//if summer is NOT found, -1 is returned.
if(sentence.toLowerCase().indexOf('summer') !=-1)
{
sentence = sentence.replace("summer", "XXXXX");
flag = false;
}
//if 19 is NOT found, -1 is returned.
if(sentence.toLowerCase().indexOf('19') !=-1)
{
sentence = sentence.replace("19", "XX");
flag = false;
}

var y = new Boolean(true);
if(flag == y)
{
document.getElementById("demo").innerHTML =sentence;
}else
{
document.write(sentence)
}


}
</script>

</body>
</html>

Output:

Add a comment
Know the answer?
Add Answer to:
Question #4 Write a JavaScript function HideMe() that takes a user specified sentence and hides a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CODE: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as...

    CODE: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as input. The output is the sentence after censoring all the matching words in the sentence. Censoring is done by replacing each character in the censored word with a * sign. For example, the sentence "hello yes no", if we censor the word yes, will become "hello *** no" Note: do not censor the word if it is part of a larger word. For example,...

  • PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """...

    PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as input. The output is the sentence after censoring all the matching words in the sentence. Censoring is done by replacing each character in the censored word with a * sign. For example, the sentence "hello yes no", if we censor the word yes, will become "hello *** no" Note: do not censor the...

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT