this time capture at least three numbers (a year, a month, and a date as a minimum) to make a date. You should prompt the user for a year and then a month and then a day. Use this data to create a date object. Make sure not to use the default debugging output of the date in the story. Use a date method such as toDateString to create a nice output.
Make an object and use it to store at least three nouns (names of people, places, or things) used in your story. This doesn't have to be data that you asked the user for in prompts but it could be if you wanted it to be.
The other requirements are mostly the same as last week:
Code :
<!DOCTYPE html>
<html>
<head>
<title>Story</title>
</head>
<body>
<script type="text/javascript">
var day = prompt("Enter a day
(1-30) : "); // promt is used for getting the
data feom the user
var month = prompt("Enter a Month
(1-12) : ");
var year = prompt("Enter a Year :
");
var date = new
Date(year,month-1,day);
// since js counts month from 0-11
var date_string =
date.toDateString();
var name1 = prompt("Enter a Name
: ");
var place1 = prompt("Enter a Place
: ");
var things1 = prompt("Enter a
Things : ");
var noun = {
// putting all the values
into the noun object
name :
name1,
palce :
place1,
things :
things1
};
// story made and printed in the
console
console.log(noun.name + " went to "
+noun.palce+ " at " +date_string+ " to get " +noun.things);
</script>
</body>
</html>
Get Answers For Free
Most questions answered within 1 hours.