Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a JavaScript assignment: Script 1 First, create an HTML5 page with JavaS

ID: 3678769 • Letter: T

Question

This is a JavaScript assignment:

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

Script 1:

<!DOCTYPE html>
<html>
<body>

Enter First String :
<br>
<input type="text" id="Text1" name="TextBox1">
<br>Enter Second String :
<br>
<input type="text" id="Text2" name="TextBox2">

<br>
<input type="button" name="clickbtn" value="Display Result">


<script>
function search() {
             
                var first_string = (document.getElementById("Text1").value);
                var second_string= (document.getElementById("Text2").value);
              

               var index=second_string.indexOf(first_string);
               if(index!=-1)
              alert("String found at index "+index);
               else
              alert("String not found");

              
              
   
            }
</script>

</body>
</html>

Script 2

<!DOCTYPE html>
<html>
<body>


<input type="button" name="current time" value="current">
<input type="button" name="24hoursbefore" value="24hoursbefore">
<input type="button" name="before10years" value="before10years">
<input type="button" name="weekbefore7" value="weekbefore7">


<script>
function now() {
                   var today = new Date();
                alert(today);

              
              
   
            }
          
function before24() {
                   var today = new Date();
              
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
   var date = today.getDate();
   //alert(date//);
    var month = today.getMonth();
   var monthname=monthNames[month];
       //alert(month);
   var year = today.getFullYear();
       //alert(year);

   var hours = today.getHours();
    //var days = today.getDay();
   //   alert(days);
    var minutes = today.getMinutes();
   var sec = today.getSeconds();
   if(monthname=="January" && date==1)
   {
   monthname="December";
   date=31;
   year=year-1;
  
   }
  
   else if(monthname=="January"||monthname=="May"||monthname=="July" ||monthname=="August" ||monthname=="October" || monthname=="December"){
   if(date==1)
   {
   monthname=monthNames[month-1];
   date=30
   }
   
     }  
   else if(monthname=="April" ||monthname=="June" || monthname=="September"||monthname=="July" ||monthname=="November")
   {
   date=31;
   monthname=monthNames[month-1];

   }
   else if(monthname=="March" && date==1)
   {
      monthname=monthNames[month-1];
        date=28

      
   }
   else
   {
  
   date=date-1;
   }
   alert(monthname+" "+date+" "+year+" "+hours+":"+minutes+":"+sec);          

           }
      

function before10years() {
                   var today = new Date();
              
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
   var date = today.getDate();
   //alert(date//);
    var month = today.getMonth();
   var monthname=monthNames[month];
       //alert(month);
   var year = today.getFullYear();
       //alert(year);

   var hours = today.getHours();
    //var days = today.getDay();
   //   alert(days);
    var minutes = today.getMinutes();
   var sec = today.getSeconds();
  
  
   year=year-10;
  
   alert(monthname+" "+date+" "+year+" "+hours+":"+minutes+":"+sec);          

           }  


function week() {
                   var today = new Date();
              
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
   var date = today.getDate();
   //alert(date//);
    var month = today.getMonth();
   var monthname=monthNames[month];
       //alert(month);
   var year = today.getFullYear();
       //alert(year);

   var hours = today.getHours();
    //var days = today.getDay();
   //   alert(days);
    var minutes = today.getMinutes();
   var sec = today.getSeconds();
   if(monthname=="January" && date==1)
   {
   monthname="December";
   date=25;
   year=year-1;
  
   }
  
   else if(monthname=="January"||monthname=="May"||monthname=="July" ||monthname=="August" ||monthname=="October" || monthname=="December"){
   if(date==1)
   {
   monthname=monthNames[month-1];
   date=24
   }
   
     }  
   else if(monthname=="April" ||monthname=="June" || monthname=="September"||monthname=="July" ||monthname=="November")
   {
   date=25;
   monthname=monthNames[month-1];

   }
   else if(monthname=="March" && date==1)
   {
      monthname=monthNames[month-1];
        date=21

      
   }
   else
   {
  
   date=date-7;
   }
   alert(monthname+" "+date+" "+year+" "+hours+":"+minutes+":"+sec);          

           }
                  
          
</script>

</body>
</html>

Script 3

<!DOCTYPE html>
<html>
<body>

Enter First number :
<br>
<input type="text" id="Text1" name="TextBox1">
<br>Enter Second number :
<br>
<input type="text" id="Text2" name="TextBox2">

<input type="button" name="Add" value="Add">
<input type="button" name="subtract" value="subtract">
<input type="button" name="multiply" value="multiply">
<input type="button" name="divide" value="divide">
<input type="button" name="Mod" value="Mod">

<script>
function add() {
                  var first_num = parseInt(document.getElementById("Text1").value);
                var second_num= parseInt(document.getElementById("Text2").value);

               alert(first_num+second_num);
              
   
            }
          
function subtract() {
              var first_num = parseInt(document.getElementById("Text1").value);
                var second_num= parseInt(document.getElementById("Text2").value);

               alert(first_num-second_num);    

           }
      

function multiply() {
              var first_num = parseInt(document.getElementById("Text1").value);
                var second_num= parseInt(document.getElementById("Text2").value);

               alert(first_num*second_num);    

           }  


function divide() {
                         
var first_num = parseInt(document.getElementById("Text1").value);
                var second_num= parseInt(document.getElementById("Text2").value);
if(second_num!=0)
alert(first_num/second_num);
else
alert("Divide by zero");

           }
          
function Mod() {
                         
var first_num = parseInt(document.getElementById("Text1").value);
                var second_num= parseInt(document.getElementById("Text2").value);
if(second_num!=0)
alert(first_num%second_num);
else
alert("Mod by zero");

              


           }                  
          
</script>

</body>
</html>

Script 4

<!DOCTYPE html>
<html>
<body>

Enter number :
<br>
<input type="text" id="Text1" name="TextBox1">

<input type="button" name="Asciivalue" value="Asciivalue">

<script>
function AsciiValue()
{
var first_num = (document.getElementById("Text1").value);

               alert("The ASCII representation is "+first_num.charCodeAt(0) );
              
   
            }
          
          
</script>

</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote