Connecting Tech Pros Worldwide Forums | Help | Site Map

Total newbie at javascript and having a very hard time...NEED HELP!!!

Newbie
 
Join Date: Oct 2009
Posts: 2
#1: Oct 8 '09
If anyone can help me with this I would be very appreciative. I have just started this class and I feel like I am over my head big time. But I need to take this course to finish. this is one of my assignments and I am completely lost. I am not sure how to write the code for this project and I could use any help that will nudge me in the write direction to complete this. I know that this is a very long request by I won't lie to you I need your expertise on this. Thanks in advance to all who can help me!

I have to create a function named ranImg( ). Inside of the parentheses, use a parameter named num.

Then I have to return a value calculated by taking the value held by the placeholder num and add one to it. Then round the value down to the nearest integer. Now multiply this value by a randomly generated value by JavaScript.

After that I have to create a new function named genNum( ). In the first line of the function, pass the results of the ranImg( ) function to a variable named number. In the genNum( ) function, be sure to use a parameter value of 9.
In the next line of the function, use a document.write( ) method and insert the string "<img src='"+number+".gif' alt='' />" in the method.

Then I have to create a third function named showDays( ). In the first line of this function, pass all date and time information to a variable named today. In the next line of the function, pass the date and time information for September 21, 2007, 2:00 PM to a variable named proj_date.

In the next line of the function, determine the difference between the start of the Project Fair and today’s date and then convert the value into days. Pass the results of this to a variable named days_left.

Round the number of days left to the Project Fair and pass this value to a variable named display_days. Return this calculated value.

Call the function showDays( ) and pass the results of the function to a variable named day.

Place inside the header of this file a script tag and call the file asr_elem.js. Insert a closing script tag immediately after this.

Locate the script tags in the body of the file. Insert a document.write method in between these tags and write to the Web page the value held in the variable named day.

In the header of this file, link to this page the external JavaScript file named asr_elem.js.

Scroll down and in the table find the script tags placed in the table. Enter the function genNum( ) five times in between these script tags.

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,656
#2: Oct 8 '09

re: Total newbie at javascript and having a very hard time...NEED HELP!!!


for most of the task, the coding is told within the text, insofar it should not be a problem. But you will certainly need a JS reference site. there’s a number of them listed in the "Sticky: Offsite Links". my personal favourite is MDC

There’s one point of objection though. every Javascript expert will strongly discourage the use of document.write(). this can be done way better through the DOM.

PS. check out the Date() object.
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 350
#3: Oct 8 '09

re: Total newbie at javascript and having a very hard time...NEED HELP!!!


You have told everything what to be done. Where you are struck?

Regards
Ramanan Kalirajan
Newbie
 
Join Date: Oct 2009
Posts: 2
#4: Oct 9 '09

re: Total newbie at javascript and having a very hard time...NEED HELP!!!


This is what I am stuck on. I have read the chapter but not sure of how to write it. I have provided what I think is the basic code but i still need to make it work. any help would be great. Thanks!


Expand|Select|Wrap|Line Numbers
  1. //
  2. function ranImg(num) {
  3.     document.write();
  4.     document.write();
  5.     document.write();
  6.         return    ;
  7. }
  8.  
  9. //
  10. function genNum(9) {
  11.     var number ();
  12.     document.write("<img src='"0".gif' alt='' />" );
  13.  
  14. }
  15.  
  16. //
  17. function showDays(){
  18.     var today ();
  19.     var proj_date ();
  20.     var days_left();
  21.     var display_days();
  22.     return();
  23.  
  24.     var day(showDays);
  25.  
  26. )
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 350
#5: Oct 12 '09

re: Total newbie at javascript and having a very hard time...NEED HELP!!!


Hi,
Instead of using document.write(). U can have a div and update the contents of the div whenever needs. Since document.write() clears the browser content. You can change the contents for only one div instead changing the whole HTML.

A small Ex:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE> New Document </TITLE>
  5. <META NAME="Generator" CONTENT="EditPlus">
  6. <META NAME="Author" CONTENT="">
  7. <META NAME="Keywords" CONTENT="">
  8. <META NAME="Description" CONTENT="">
  9. <script type="text/javascript">
  10. var count=0;
  11. function addContent()
  12. {
  13.     count++;
  14.     document.getElementById('myDiv').innerHTML += "<br/>Updated Count No "+count+"<br/>";
  15. }
  16. </script>
  17. </HEAD>
  18.  
  19. <BODY>
  20. <div id="myDiv">
  21.     This is the default Static Content
  22. </div>
  23. <br/>
  24. <input type="button" value="update Div" onclick="addContent()"/>
  25. </BODY>
  26. </HTML>
This above code is a small piece of changing a particular content. You can do whatever you need.. Please post back if you have any problems/queries

Thanks and Regards
Ramanan Kalirajan
Reply