Question

In: Computer Science

Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...

Write the below code to use HTML and JavaScript.

1.

a) Write a JavaScript program to display the current day and time.
b) Write a JavaScript program to print the contents of the current window.  

c) Write a JavaScript program where the program takes a random integer between 1 to 10
d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user).
e)Write a JavaScript program to create a new string from a given string changing the position of first and last characters. The string length must be greater than or equal to 1.
f)Write a JavaScript program to check whether a string starts with 'Java' and false otherwise

Solutions

Expert Solution

Answer 1) The answer for subparts is below: I have answered 4 subparts

(A) The HTML and javascript code is below.

<head>
<title>
displaying current date and time
</title>
</head>
  
<body>
<script>

// creating a date object
var todayDate = new Date();
  
var todayDay = todayDate.getDay();
  
// Array of days.
var weekday = ['Sunday', 'Monday', 'Tuesday',
'Wednesday', 'Thursday', 'Friday', 'Saturday'
];

// displaying date and time
document.write("Today is : " + weekday[todayDay]);
document.write("<br/>");
  
// getting hour from date object
var hours = todayDate.getHours();
var am_pm = hours >= 12 ? 'PM' : 'AM';

hours = hours % 12;
  
// when we get hours=0 from 12 % 12 = 0 from above then set hour to 12 ie noon 12
hours = hours ? hours : 12;
var minutes = todayDate.getMinutes();
minutes = minutes < 10 ? '0' + minutes : minutes;
  
var myTime = hours + " " + am_pm + " : " + minutes ;
document.write("\tCurrent time is : " + myTime);
</script>
</body>
  
</html>

OUTPUT SCREENSHOT

(B) The Code is below:

<!DOCTYPE html>
<html>
<head>
<title>Print the content current window.</title>
</head>

<body>
<p> Window.print() method is used to print the content.</p>
<p>Click the button to print the current page.</p>
<button onclick="print_current_page()">Print this page</button>

<script type="text/javascript">
   function print_current_page()
{
window.print();
}

</script>
</body>

</html>

OUTPUT SCREENSHOT

(C) The Code is below:


<html>
<head>
<title>Radom number</title>
</head>
<body>

<script type="text/javascript">
  
   var num = Math.floor(Math.random() * 11);
   document.write("The random number is "+ num);

</script>


</body>
</html>

(D) The Code is below.


<html>
<head>
<title>Radom number</title>
</head>
<body>
<!-- form to take input -->
<form onsubmit="return false;">
Enter First number: <br>
<input type="number" id="fnum" name="number1"> <br>
Enter Second number: <br>
<input type="number" id="snum" name="number2"> <br> <br>

<button onclick="multiply()">multiply</button>
<button onclick="divide()">division</button>

</form>

<h3 id='result'></h3>

<script type="text/javascript">
  
// function to print multiply
function multiply(){
var num1 = document.getElementById("fnum").value;
var num2 = document.getElementById("snum").value;
document.getElementById('result').innerHTML= "Result of multiply: "+ num1*num2;
  
}

// function for division.
function divide(){
var num1 = document.getElementById("fnum").value;
var num2 = document.getElementById("snum").value;
document.getElementById('result').innerHTML= "Result of divide: "+ num1/num2;
}

</script>


</body>
</html>


Related Solutions

Use HTML&CSS& JavaScript to: 3-4) Write a JQuery Ajax program which can communicate with flicker to...
Use HTML&CSS& JavaScript to: 3-4) Write a JQuery Ajax program which can communicate with flicker to get the last pictures taken from any place or related to any concept(s) the user has written in a textbox, say Sydney, train. Some information associated with the image like its topic, time taken, and its link needs to be appeared with it. 3-5) Develop a server which can serve the file you developed in 3-4. 3-6) Add a plugin to the real jQuery...
The code to create a Search/Filter Data with Javascript or html from html page.
The code to create a Search/Filter Data with Javascript or html from html page.
Write an Html Page that uses JavaScript Program to make a Blackjack Game. I need to...
Write an Html Page that uses JavaScript Program to make a Blackjack Game. I need to write an html file (P5.html) that uses JavaScript program to create a Blackjack game. 1. Blackjack Games Rules: a. The object of the game is to "beat the dealer", which can be done in a number of ways: • Get 21 points on your first two cards (called a blackjack), without a dealer blackjack; • Reach a final score higher than the dealer without...
write php code for buying and selling web using sql, javascript ,html ,css style
write php code for buying and selling web using sql, javascript ,html ,css style
JAVASCRIPT HTML I'm looking to make a function that will take a postal code in a...
JAVASCRIPT HTML I'm looking to make a function that will take a postal code in a text box. The function jobs is to basically make sure the first letter of the postal code starts with these letters. ('A') ('N") ('W') ('F'). If the first letter of the postal code does not match up then an error to the user is sent.
For this assignment, you will write a tic-tac-toe application in HTML and JavaScript, using an HTML...
For this assignment, you will write a tic-tac-toe application in HTML and JavaScript, using an HTML <canvas> tag. The game will be played "hot seat" where players take turns using the same device. Requirements: The canvas should be 600px tall and wide, with the gameplay area occupying most of the canvas. The X's and O's may be drawn using polygons or large-font text The grid should be drawn using polygons, specifically long, thin rectangles Before & between games, the canvas...
JavaScript 1. FizzBuzz Submit js file with functioning code Write a program that uses console.log to...
JavaScript 1. FizzBuzz Submit js file with functioning code Write a program that uses console.log to print all the numbers from 1 to 120, with two exceptions. For numbers divisible by 4, print "Fizz" instead of the number, and for numbers divisible by 10 (and not 4), print "Buzz" instead. When you have that working, modify your program to print "FizzBuzz", for numbers that are divisible by both 4 and 10 (and still print "Fizz" or "Buzz" for numbers divisible...
Please take the code below and add some javascript to it. Please use javascript inline. Please...
Please take the code below and add some javascript to it. Please use javascript inline. Please be sure to specify within the webpage with something like 'Click here' too show what was done and how to activate it. Please post in a format that can be directly copied. Thank you in advance HINT: add some fun widgets to the page index-css.html: <!DOCTYPE html> <html lang="en"> <head> <!-- title for web page --> <title>Index-CSS Page</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1">...
Make sure it works on jsfiddle and keep the code seperate html: css: javascript: -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Make sure it works on jsfiddle and keep the code seperate html: css: javascript: ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Assignment You should already have some experience with jQuery and some simple experience with JSON (from charting). In this assignment we will be creating some JSON data, parsing it, and displaying it. Step 1 – If you are not familiar with JSON you should complete the JSON tutorial at w3schools Step 2- You will now create a JSON file to represent some data of your...
2. The HTML document on the following page consists of JavaScript code executed when the document...
2. The HTML document on the following page consists of JavaScript code executed when the document is loaded. It prompts the user for his/her name (first and last names) then outputs the greeting “Hello Mr. _____!” or “Hello Ms. _____!” (where _____ is the user’s last name) depending on whether the first name is recognized as a male name. (In the code, only three male names are checked; a realistic program would check many more names.) We allow for the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT