# Question & Answer: Create a function called tell_user() that pops up an alertbox with some inspirational message. Call…..

please use javascript so answear the question.

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Create a function called tell_user() that pops up an alertbox with some inspirational message. Call…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

Create a function called tell_user() that pops up an alertbox with some inspirational message. Call the function to make sure it works. Create a function called square_it() that takes one argument: an integer. The function will compute the square of the number and return this as its return value and then alert() the results to the user. parselnt (prompt(“Please enter an integer to square: “, “”)): Create a function that takes a single argument: a phone number. The function should return true if the phone number has either seven digits or ten digits, false otherwise. Create a function that takes a sentence. The function should return true if the string contains the substring “sample”, false otherwise.

Problem 1:

<html>

<!– Scripting section –>
<script type=”text/javascript”>

//Function definition
function tell_user()
{
//Displaying a message box to user
alert(“An investment in knowledge always pays the best interest.”);
}

</script>

<!– Calling function at onload event of body –>

</body>

</html>

Sample Run:

______________________________________________________________________________________________

Problem 2:

<html>

<!– Scripting section –>
<script type=”text/javascript”>

//Function definition
function square_it(num)
{
//Computing square of a number
var result = num * num;

//Displaying a message box to user
}

//Function that process the square_it function
function processSquare()
{
var num = parseInt(prompt(“Please enter an integer to square: “, “”));

//Calling square_it function
square_it(num);
}

</script>

<!– Calling function at onload event of body –>

</body>

</html>

Sample Run:

__________________________________________________________________________________________________________________

Problem 3:

<html>

<!– Scripting section –>
<script type=”text/javascript”>

//Function definition
function chkPhoneNumber(phoneNumber)
{
//For counting number of digits
var cnt = 0;

//Counting digits
while( phoneNumber >= 1 )
{
//Extracting digit
phoneNumber = phoneNumber / 10;

//Accumulating count
cnt++;
}

//Checking number of digits
if(cnt == 7 || cnt == 10)
{
return true;
}
else
{
return false;
}
}

//Function that process phone number
function processPhoneNumber()
{
var phNum = parseInt(prompt(“Enter phone number: “, “”));

//Calling function by passing phone number
if(chkPhoneNumber(16889555))
{
alert(” Phone number has seven digits… “);
}
else if(chkPhoneNumber(5589589771))
{
alert(” Phone number has ten digits… “);
}
else
{
alert(” Not of valid length!!! “);
}
}

</script>

<!– Calling function at onload event of body –>

</body>

</html>

Sample Run:

______________________________________________________________________________________________

Problem 4:

<html>

<!– Scripting section –>
<script type=”text/javascript”>

//Function definition
function chkSentence(sentence)
{
//Finding index of sub-string sample in sentence
if(sentence.indexOf(“sample”) != -1)
{
return true;
}
else
{
return false;
}
}

//Calling function
alert(chkSentence(‘This is just a sample program’));

</script>