Skip to content

Instantly share code, notes, and snippets.

@codegoalie
Created May 4, 2012 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegoalie/2591846 to your computer and use it in GitHub Desktop.
Save codegoalie/2591846 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>John Doe's web page</title>
</head>
<body>
<script type="text/javascript">
// Use a popup box here to read the user name
// and write a personalized greeting
{
var name=prompt("Please enter your name","Harry Potter");
if (name!=null && name!="")
{
document.write("<h2>Hello " + name + "!</h2>");
}
}
function date()
{
var d = new Date();
// Prints the current date
// using document.write statements
// and d.getMonth() and d.getDate() methods
var date_div_element = document.getElementById('date_div');
date_div_element.innerHTML = 'Today is ' + (d.getMonth() + 1) + '/' + d.getDate() + '/' + d.getFullYear();
}
function time()
{
var d = new Date();
// Prints the current time
// using document.write statements
// and d.getHours() and d.getMinutes() methods
var time_div_element = document.getElementById('time_div');
time_div_element.innerHTML = 'The time is ' + d.getHours() + ':' + d.getMinutes();
}
</script>
<h2>Welcome to John Doe's dynamic web page that uses Javascript</h2>
<p>Press a button to start.</p>
<input type="button" Name="button1" value="Display date" onclick="date()" />
<input type="button" Name="button1" value="Display time" onclick="time()" />
<div id='time_div'></div>
<div id='date_div'></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment