Web Analytics Made Easy -
StatCounter NEW at javascript and need help asap! - CodingForum

Announcement

Collapse
No announcement yet.

NEW at javascript and need help asap!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NEW at javascript and need help asap!

    Hi there. I've got a JavaScript project due tonight, and I can't seem to figure out what's going wrong with my code, seeing as I'm brand new at this.

    The problem is, I can't seem to get the HTML string to work (step 18) inside the attached file, and I can't see what I'm doing wrong. I haven't gone through all the steps yet, but as so far it's not working.

    Attached with this post is my code for it along with the pseudocode step-by-step instructions for it. Any help would be greatly appreciated, thank you
    Attached Files
    Last edited by angelita; Feb 16, 2004, 05:57 PM.
    "Without leaving the house, I know the whole universe" - Lao-Tzu

  • #2
    Since the link you posted does not work, I can only deduce that your problems stem from the fact that you do not take time reading (manuals, references, tutorials, posting guidelines) before you start writing (javascript code, posts)...
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

    Comment


    • #3
      You make that assumption from the fact that the link doesn't work? I have spent a great deal of time reading, and a great deal of time trying to figure out my own mistakes on the assignment, which requires that I do SOME reading in the very least.

      Well, the link sometimes works for me and sometimes doesn't. Anyway, my question can still be answered without the link. There are pseudocode instructions attached along with my code, all I need help with is the html string there.
      Last edited by angelita; Feb 16, 2004, 05:56 PM.
      "Without leaving the house, I know the whole universe" - Lao-Tzu

      Comment


      • #4
        I made this assumption from the fact that you did not bother reading posting guidelines before making your original post. Now that I see you your source code (or lack thereoff), my assumption is confirmed.
        Vladdy | KL
        "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

        Comment


        • #5
          I glanced at the posting guidelines but you're right, I did not spend time reading through them all. I noticed that an .rtf file in wordpad was not accepted, so I tried to convert it to .txt, which obviously didn't work. Here it is again, only this time I saved it in notepad.

          This attachment only works for me if I press "save" after clicking it first instead of opening it *without* saving first. Same with the one I attached above.
          Attached Files
          Last edited by angelita; Feb 16, 2004, 06:17 PM.
          "Without leaving the house, I know the whole universe" - Lao-Tzu

          Comment


          • #6
            I'm talking about the stupid "code protector" on the page you asking to analyze for you.
            Vladdy | KL
            "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

            Comment


            • #7
              If I'm correct, you mean the code protector for the link I provided? I just posted that link in order to see a sample of what I'm trying to create. That was a sample provided my instructor, so of course he's going to protect the code...otherwise what's the point in doing the assignment. *My* code is in the attachment which also includes the instructions for the assignment.
              "Without leaving the house, I know the whole universe" - Lao-Tzu

              Comment


              • #8
                And after taking my time to look at the file you attached I can only suggest you drop that class or ask for another instructor. You are being taught things that were depreciated 5 years ago and are no longer correct.
                Vladdy | KL
                "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

                Comment


                • #9
                  Interesting. Can you give me an example?
                  "Without leaving the house, I know the whole universe" - Lao-Tzu

                  Comment


                  • #10
                    there is the following bugs at least

                    a ; after an if()
                    no space after a new
                    and missing a " somewhere for were I will not say

                    oh and Math.round used on random makes the values appear unrandom

                    Comment


                    • #11
                      oh and just a hint is you use IE or any other browser they usually somewhere display what lines that bugs them

                      Comment


                      • #12
                        Hehe well thank you I'll check it all out
                        "Without leaving the house, I know the whole universe" - Lao-Tzu

                        Comment


                        • #13
                          Sure:
                          1. Transitional doctype is used for backward compatibility with OLD/EXISTING web pages. New web pages should be created using Strict doctype.
                          See first paragraph in Transitional DTD: http://www.w3.org/TR/1999/REC-html40.../loosedtd.html

                          2. newImage() is not defined or is some proprietory thing. DOM functionality (http://www.w3.org/TR/2000/REC-DOM-Le...1113/core.html)
                          should be used: imageElement = document.createElement('image');

                          3. Polluting global scope with variables is a bad practice and should be discouraged in favor of object oriented approach

                          4. Smile/Frown functionality can be easily implemented with CSS

                          5. document.myImage - is IE proprietory way of accessing page elements. Should use DOM: document.getElementById('imageID');

                          6. XHTML is defined in windowless enviroment, therefore creation of new windows should be discouraged (and definitely not taught).

                          7. align attribute was depreciated and the use of <font> element screams of incompetence.

                          Here is your "instructors" code which serves as an example of how NOT to do things:
                          Code:
                          <HTML>
                          <HEAD>
                          <SCRIPT LANGUAGE="JavaScript"> 
                          <!-- hide this stuff from older browsers
                          pic1=new Image(200,200)
                          pic1.src="images/smile.gif"
                          pic2=new Image(200,200)
                          pic2.src="images/frown.gif"
                          
                          var randomnum
                          
                          function im(){}
                          
                          function Smile()
                          { document.myimage.src=pic1.src
                          }
                          
                          function Frown()
                          { document.myimage.src=pic2.src
                          } 
                          
                          function FindNumber()
                          {randomnum=Math.round(9 * Math.random())+1
                          window.status=randomnum
                          }
                          
                          function DisplayNumber()
                          { var guess=prompt("Time to guess! Enter a number between 1 and 10:","")
                            var OpenWindow=window.open("","newwin2","height=350,width=350,status=yes");
                            if (guess==randomnum)
                             { var myTitle="Guessed Right"
                               var myMessage="Congratulations!<br>You guessed right!"
                          	 var myFace=pic1.src
                             } 
                            else
                             { var myTitle="Guessed Wrong"
                               var myMessage="Sorry!<br>You guessed wrong!"
                               var myFace=pic2.src
                             }
                            var wintext="<HTML>"+ "<TITLE>" + myTitle + "</TITLE>"
                            + "<body onLoad = im()>"
                            + "<DIV align='center'>"
                            +"<IMG SRC=' " + myFace + " ' BORDER=0>"
                            + "<P>"+ "<FONT SIZE=+1>" + myMessage + "</FONT>"
                            + "<HR WIDTH='60%'><P>"
                            + "<A HREF='' onClick='self.close()'>Close</A>"
                            + "<P></DIV>"+ "</BODY>"+ "</HTML>"
                            OpenWindow.document.write(wintext)
                            OpenWindow.status=myTitle 
                          }
                          
                          // end the hiding comment --></SCRIPT>
                          </HEAD>
                          <BODY><center><H1>Guessing Game</H1>
                          <H3>You will be asked to guess a number between 1 and 10. 
                          <br>Click the button when you are ready...</H3>
                          <A HREF="specialproject4.htm"  onMouseOver="Frown()" OnMouseOut="Smile()">
                          <SCRIPT LANGUAGE="JavaScript"><!-- hide this stuff from other browsers
                          document.write("<IMG SRC=' " + pic1.src + " ' BORDER=0 NAME='myimage'>");
                          // end the hiding comment --></SCRIPT>
                          </A>
                          <FORM><INPUT TYPE="button" VALUE="Play!" onClick="FindNumber();DisplayNumber()"><BR></FORM>
                          </center></BODY>
                          </HTML>
                          Vladdy | KL
                          "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

                          Comment


                          • #14
                            In the interests of accuracy of vocabulary, various things are deprecated, not depreciated. Very similar words, very different meanings, like "appraised" and "apprised", or "hypercritical" and "hypocritical".

                            I am of course a member of the Pedants' Society. That is, The Society of Pedants, whose society I enjoy.
                            Last edited by Philip M; Feb 17, 2004, 03:26 AM.

                            All the code given in this post has been tested and is intended to address the question asked.
                            Unless stated otherwise it is not just a demonstration.

                            Comment


                            • #15
                              OK, I just gotta chime in

                              Gee, Vladdy, wazzup dude? Uncharacteristicly harsh, are we not? Seems to me rather than stating problems as if they were self-evident, give the specifices; after all this is a *learning* forum.

                              Nonetheless there are many valid issues here.

                              The code does seem to be an eclectic mix of stuff. Given all I've seen, I'm guessing the instructor is a "fellow" at the local community college (gee, RB uncharacteriscly harsh, are we not? ). It's hard to give critical analysis (vis-a-vis mere criticism) when one is not familiar w/ the circumstances (course time length, goals, prerequesites, etc.) ....

                              The hand holding comments throughout the source listing strongly suggest a rank-novice audience, yet the instructor asks for writing event handlers (#20, just under the <form> tag). OK, maybe the instructor means an "onclick event", but that's different than an "event handler." Find a different description then.

                              As for "use of <font> element screams of incompetence" - not necessarily. If CSS is fully "off topic" then it's OK. If CSS is a future lesson, then this will serve as an excellent object lesson later. Replacing dozens of tortured <font> tags w/ clean, elegant CSS rules surely made me a convert!


                              1. The doctype is perhaps the least understood thing on any given web page. I certainly haven't run across much on it; and the inconsistant implementation of *anything* across the myriad of browsers (not to mention "legacy" browsers still out there) makes it difficult to know just what's "right." We settle for what seems to work and get on to more important things.

                              2. I disagree that the round function tends to make the numbers 'appear unrandom'. The formula is a variation on the technique for generating random numbers w/in a range of integers - like simulating a dice roll. Unless there is some essoteric quirkyness in javascript math, the technique shown most likely is just as good.

                              3. One of my favorite pet peeves is that "how to code" is not taught in programming classes. This example appears to be no different.

                              4. Very inconsistant use of semi-colon's to terminate statements. This does one of two things: either a) confuses the student because of the apparent random use or b) teaches poor coding discipline.

                              Oh, the seemingly random use of "/>" to terminate tags is also curious.

                              Personally I say "always use semi-colons" They're required in C and Java so get used to it. Second, if you ever use a "code scruncher" to squeeze out superfluous characters (like line returns) then the code will break w/out semi-colons. And finally - and most importantly - code modifcation is less error prone when code is *consistant*.

                              5. Poorly named functions. "findNumber()" does not find a number, nor is it named in the context of the program. "generateRandomNumber()" would be more accurate, but that's is not w/in the context of the program (a number guessing game). Maybe "createNumberToGuess()" would be better.

                              6. Walking on global namespace with muddy feet is just part of the larger issue of programming interface. By using global variables in functions, rather than passing them to the function call parameter list and then explicitly returning values - one "hides the interface." Lucky for us that the ill-named "findNumber()" is so short, least we miss the fact that it uses a globally defined variable and "returns" a random number.

                              Comment

                              Working...
                              X