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

Problem 1 Create a function called tell_user) that pops up an alertbox with some inspirational message. Call the function to make sure it works. Problem 2 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. NOTE: When a number is entered by the user via a prompt, some browsers store it as a string and not an integer. As a result, you cannot perform number-like operations on it (add 2 to 3, divide 2 into 6, etc...) You must, in this case, make sure that when you pass the number entered from the user to the function, you convert it from a string to a number. The following code snippet will prompt the user for a number, and will make sure it is stored as a number and not a string. parselnt (prompt(Please enter an integer to square: , ); Problem 3 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. Problem 4 Create a function that takes a sentence. The function should return true if the string contains the substring sample, false otherwise.

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
Order Essay

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.

Expert Answer

 

Problem 1:

<html>

<head>

<!– 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>

</head>

<!– Calling function at onload event of body –>
<body onload=”tell_user()”>

</body>

</html>

Sample Run:

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

______________________________________________________________________________________________

Problem 2:

<html>

<head>

<!– 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
alert(“Square(“+num+”) = ” + result);
}

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

//Calling square_it function
square_it(num);
}

</script>

</head>

<!– Calling function at onload event of body –>
<body onload=”processSquare()”>

</body>

</html>

Sample Run:

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

__________________________________________________________________________________________________________________

Problem 3:

<html>

<head>

<!– 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()
{
//Reading phone number from user
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>

</head>

<!– Calling function at onload event of body –>
<body onload=”processPhoneNumber()”>

</body>

</html>

Sample Run:

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

______________________________________________________________________________________________

Problem 4:

<html>

<head>

<!– 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>

</head>

<body>

</body>

</html>

Sample Run:

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

Still stressed from student homework?
Get quality assistance from academic writers!