0

I having trouble returning the string in this function. For starters I'm a beginner who just started learn javascript a week ago, sorry in advance if I word things wrong. I was told to declare a variable named timeStr to equal the value returned from the showDate() function as well as mapNum to the getMap() function. Both the showDateTime() and getMap() function are in a file that I'm accessing called datetime.js. I would just like some input on where I made the mistake and how to correct it, thanks.

<script src="datetime.js" type="text/javascript"></script>
<script type="text/javascript">
function test(){
/*
   timeStr is a text string containing the current date and time
   mapNum is the number of the map to display in the planisphere
/*
var timeStr = showDateTime();
var mapNum = getMap();
}
</script>

UPDATE: The datetime.js is below:

/*
   New Perspectives on JavaScript, 2nd Edition
   Tutorial 1
   Case Problem 1

   Function List:
   showDate
      Used to return a text string containing the current date and time.
   getMap
      Used to the determine the current sky map number to display with the online        planisphere

*/


function showDateTime() {
   var thisDate = new Date();
   var thisWDay=thisDate.getDay();
   var thisDay=thisDate.getDate();
   var thisMonth=thisDate.getMonth();
   var thisYear=thisDate.getFullYear();
   var mName = new Array("January", "February", "March", "April", "May", 
       "June", "July", "August", "September", "October","November", "December");
   var hours=thisDate.getHours();
   var minutes=thisDate.getMinutes();
   ampm = hours >=12 ? " pm" : " am";
   hours = hours > 12 ? hours-12 : hours;
   minutes = minutes < 10 ? "0"+minutes : minutes;
   return mName[thisMonth]+" "+thisDay+", "+thisYear + ", " + hours + ":" + minutes + ampm;
}

function getMap() {
   thisTime = new Date();
   hour = thisTime.getHours();
   month = thisTime.getMonth();
   mapNumber = (month*2+hour)%24;
   return mapNumber;
}
4

3 回答 3

4

You've commented everything out.

Change

/*
   timeStr is a text string containing the current date and time
   mapNum is the number of the map to display in the planisphere
/*

to

/*
   timeStr is a text string containing the current date and time
   mapNum is the number of the map to display in the planisphere
*/
于 2012-09-14T16:21:19.213 回答
0

As you can probably see by the syntax highlighting, you haven't terminated your comment correctly.

/* begins a multi-line comment and */ ends it.

于 2012-09-14T16:21:45.423 回答
0

Your comment should end with */ and not /* If you look at the syntax highlighting in your question you can see it's all greyed out.

于 2012-09-14T16:21:47.570 回答