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 VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file that uses createElement and appendChild to dynamically insert three paragraphs when a button is clicked. (b) Create a HTML file that includes JavaScript that is similar to: let recs = [“my item …1”,”my item…2”, …] i.e. an array that contains several CSV item records. When the user clicks a button, each array element will be rendered as a list element. Use a HTML list....
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.
For both JavaScript and HTML: ---------------------------------------------------- Write and test JavaScript scripts for the two exercises that...
For both JavaScript and HTML: ---------------------------------------------------- Write and test JavaScript scripts for the two exercises that follow, debug (if necessary).  When required to write a function, you must include a script to test the function with at least two different data sets.  In all cases, for testing, you must write an HTML file that references the JavaScript file. Output an HTML table of the numbers from 2 to 8 along with their squares and cubes. Create a function titled counter that takes...
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 an HTML/Javascript canvas program that displays a black dot in the center after the user...
Write an HTML/Javascript canvas program that displays a black dot in the center after the user presses the 's' button on the keyboard. Hint: Canvas size should be 500x500 and the black dot should only appear after pressing 's'.
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
Need to write a program and part 1 of the program is to write an HTML...
Need to write a program and part 1 of the program is to write an HTML code, here are the parameters, but I am new to HTML and I am confused as to how to write this. 1) HTML file shall:         - have your name(s) somewhere near the top, as a comment.         - be a complete html document with appropriate html tags.         - have 1 form with 2 parts, described as follows:         part 1:             -...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT