This is a javascript assignment. There are 4 parts. I copy pasted the entire ass
ID: 3679607 • Letter: T
Question
This is a javascript assignment. There are 4 parts. I copy pasted the entire assignment, so I have no more information to give. Please read carefully. I do downvote, and this has been answered wrong twice...by the same person.
Script 1
First, create an HTML5 page with JavaScript that prompts the user for two strings. Then create a button that will invoke a JavaScript function. The function will be scripted to search the second prompt for the first prompt. In other words, the program will search the second string entered to see whether it contains the first string entered. If the string is found, alert the user with the index position at which the string was found. If the string is not found, provide the user with an appropriate message.
Script 2
Next, create another HTML5 page with JavaScript that contains four buttons. Each button when clicked should cause an alert dialog to display a different time or date in relation to the current time. The first button is a Now button that alerts the current date and time. The second button is a Yesterday button that alerts the time and date 24 hours ago. The third button is a 10 Years Ago button that alerts the time and date 10 years ago. The fourth button is a One Week from today button that alerts the time and day one week from today.
Script 3
Now, create an HTML5 page with JavaScript that tests at least 5 Math functions. Output the results in tabular format. Indicate each Math function tested, the values passed as arguments and the result of each function.
Script 4
Finally, create an HTML5 page with JavaScript that inputs an integer value and outputs the corresponding ASCII character for the integer entered.
Explanation / Answer
Code for Script 1
<html>
<head>
<h4><center>Script 1</center></h4>
<script>
function checkStr()
{
var str1 = document.form1.t1.value;
var str2 = document.form1.t2.value;
if(str2.includes(str1))
{
var n = str2.indexOf(str1);
alert(" " + n);
}
else
{
alert("String 1 not Contained in String 2");
}
}
</script>
</head>
<body>
<form name = "form1">
<table align = "center">
<tr><td>Enter String 1: <input type = "text" name = "t1"></td></tr>
<tr><td>Enter String 2: <input type = "text" name = "t2"></td></tr>
<tr><td><input type = "button" value = "CLICK"></td></tr>
</table>
</form>
</body>
</html>
Code for Script 2
<html>
<head>
<h4><center>Script 2</center></h4>
<script>
function getDate(str)
{
if(str=="now")
{
var now_date = new Date();
document.getElementById("d").innerHTML = "Today's date is : " + now_date;
}
else if(str=="yesterday")
{
/*var yesterday_date = new Date();
var month = yerterday_date.getMonth();
var day = yerterday_date.getDate()-1;
var year = yerterday_date.getFullYear()
document.write(month + "/" + day + "/" + year) */
var date = new Date();
date.setDate(date.getDate() - 1);
document.getElementById("d").innerHTML = "Yesterday's date is : " + date ;
}
else if(str=="10_years_ago")
{
var ten_years = new Date();
ten_years.setTime(ten_years.valueOf() - 10 * 365 * 24 * 60 * 60 * 1000);
document.getElementById("d").innerHTML = "10 Years ago, the date is : " + ten_years ;
}
else if(str=="one_week")
{
var Date();
one_week.setTime(one_week.valueOf() + 7 * 24 * 60 * 60 * 1000);
document.getElementById("d").innerHTML = "One Week from now, the date is : " + one_week ;
}
}
</script>
</head>
<body>
<form name = "form1">
<table align = "center">
<tr><td><input type = "button" value = "NOW"></td><td> </td>
<td><input type = "button" value = "YESTERDAY"></td><td> </td>
<td><input type = "button" value = "10 YEARS AGO"></td><td> </td>
<td><input type = "button" value = "1 WEEK FROM TODAY"></td></tr>
</table>
<br><br>
<div id = "d">
</div>
</form>
</body>
</html>
Code for script 3
<html>
<head>
<h4><center>Script 3 - Testing Math Functions</center></h4>
<script>
function getRandomInt(min, max)
{
document.getElementById("d").innerHTML = Math.random() * (max - min + 1) + min;
}
function getMax(num1, num2)
{
document.getElementById("d").innerHTML = "The maximum number amoung the passed arguments " + num1 + " and " + num2 + " is " +Math.max(num1, num2);
}
function roundoff(num1)
{
document.getElementById("d").innerHTML = "The rounding off " + num1 + " is " + Math.round(num1);
}
function getSqrt(num1)
{
document.getElementById("d").innerHTML = "The Square root of " + num1 + " is " + Math.sqrt(num1);
}
function getSin(num1)
{
document.getElementById("d").innerHTML = "The Sin value of " + num1 + " is " + Math.sin(num1);
}
</script>
</head>
<body>
<form name = "form1">
<table align = "center">
<tr><td><input type = "button" value = "RANDOM FUNCTION WITHIN RANGE OF NUMBERS"></td></tr>
<tr><td><input type = "button" value = "MAX FUNCTION"></td></tr>
<tr><td><input type = "button" value = "ROUND"></td></tr>
<tr><td><input type = "button" value = "SQUARE ROOT"></td></tr>
<tr><td><input type = "button" value = "SIN VALUE"></td></tr>
</table>
<br><br>
<div id = "d">
</div>
</form>
</body>
</html>
The table for testing math functions
Function Tested
Values Passed as parameters
Ouput
Math.random() to find random numbers between a range
Min value = 10
Max vale = 20
14, 18, 12, ...
Math.max(num1, num2)
To find maximum amound the parameters passed
Num1 = 20
Num2 = 5
20
Math.round(num) to round off the float number passed as parameter
num = 20.4567
20
Math.sqrt(num) to find the square root of the parameter passed
num=3
1.7320508075688772
Math.sin(num) to find the sin value of the passed parameter
num=40
0.7451131604793488
Code for Script 4
<html>
<head>
<h4><center>Script 4 - ASCII VALUE OF INTEGER</center></h4>
<script>
function getAscii()
{
var x = document.form1.t1.value;
document.getElementById("d").innerHTML = x.charCodeAt();
}
</script>
</head>
<body>
<form name = "form1">
<table align = "center">
<tr><td>Enter Interger: <input type = "text" name = "t1"></td><td> </td><td><input type = "button" value = "GET ASCII"></td></tr>
</table>
<br><br>
<div id = "d">
</div>
</form>
</body>
</html>
Function Tested
Values Passed as parameters
Ouput
Math.random() to find random numbers between a range
Min value = 10
Max vale = 20
14, 18, 12, ...
Math.max(num1, num2)
To find maximum amound the parameters passed
Num1 = 20
Num2 = 5
20
Math.round(num) to round off the float number passed as parameter
num = 20.4567
20
Math.sqrt(num) to find the square root of the parameter passed
num=3
1.7320508075688772
Math.sin(num) to find the sin value of the passed parameter
num=40
0.7451131604793488
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.