Web Analytics Made Easy -
StatCounter Displaying a letter/character randomly generated. - CodingForum

Announcement

Collapse
No announcement yet.

Displaying a letter/character randomly generated.

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

  • Displaying a letter/character randomly generated.

    A couple of years ago I wrote a program which I would like to rewrite a little.

    Basically the program displays an image and you press the corrosponding
    button and it tells you if you are right or wrong. Because it used so many
    images it was slow to load and large in size.

    As the images are just of letters instead I thought I could use a font.
    But I dont know how I would go about manipulating a font to do that.

    What I would need to do is randomly select a letter then display it in a set
    area of set size. Also I would need to be able to link that letter to the button
    being pushed.

    This was easy enough using images, i just made an array and the random
    numbers I generated were used as column and row selects with the buttons
    having a value which matched. So if the numbers matched the random
    numbers that were generated then the answer was correct.

    I have no idea how I can do something similar with a font. could someone
    please point in in the right direction about what to read up on. Or at least
    tell me some specific terms I could search for.

    Are you able to manipulate font in this way with javascript. If not I was
    thinking about re-writing the whole thin in flash and actionscript.

    sorry if it doesnt make much sense but at the moment im not sure what
    i'm looking for exactly.

    Thanks

  • #2
    Like this?:

    <html><head>
    <style type="text/css">
    span{font: font-size: 14pt; cursorointer;}
    </style>

    <script type="text/javascript">

    function writeToSpans(){
    var span1 = document.getElementById("span1");
    var span2 = document.getElementById("span2");

    span1.innerHTML = String.fromCharCode( 65 + Math.random()*26 );
    span2.innerHTML = String.fromCharCode( 65 + Math.random()*26 );

    }
    </script>

    </head>

    <body onload="javascript:writeToSpans();">

    <span id="span1" onclick="alert('right');" style=>A</span>
    &nbsp &nbsp
    <span id="span2" onclick="alert('wrong');">B</span>

    </body></html>

    Comment


    • #3
      not sure why that emoticon appears?!?
      that css rule should read "cursor", then a colon, then "pointer"
      ill try it again:
      cursorointer

      Comment


      • #4
        hmm, strange.

        Comment


        • #5
          ill try it with spaces:
          cursor : pointer

          Comment


          • #6
            Use code tags and it won't appear. Its the pound sign. You can also stop smilies from parsing if you like but its better to use the tools of the forum. Makes things easier to read as well.
            Code:
            <html><head>
            <style type="text/css">
            span{font: font-size: 14pt; cursor:pointer;}
            </style>
            
            <script type="text/javascript">
            
            function writeToSpans(){
            var span1 = document.getElementById("span1");
            var span2 = document.getElementById("span2");
            
            span1.innerHTML = String.fromCharCode( 65 + Math.random()*26 );
            span2.innerHTML = String.fromCharCode( 65 + Math.random()*26 );
            
            }
            </script>
            
            </head>
            
            <body onload="javascript:writeToSpans();">
            
            <span id="span1" onclick="alert('right');" style=>A</span>
            &nbsp; &nbsp;
            <span id="span2" onclick="alert('wrong');">B</span>
            
            </body></html>
            ||||If you are getting paid to do a job, don't ask for help on it!||||

            Comment


            • #7
              like this?

              Code:
              i'm a newbie

              Comment


              • #8
                Say, as you are a "helpfull member", where is the nav link that shows unanswered posts?
                I had it once, but darned if i can find it again.

                Comment


                • #9
                  Thank you for your replies your code has been very useful and I have some
                  idea about how to go about it.

                  To be honest I dont really understand it right now, I never was a programmer
                  but I can play with it and hopefully work out how to use it for what I want.

                  My aim is to actually display Japanese letters and Looking at the code I dont
                  see how it knows to use the alphabet and how I would go about telling it to
                  use a japanaese font instead.

                  Again thanks very much.

                  After playing with it I still have no idea how to get it to use a different char
                  set any ideas?

                  When i alter the font size from 14 to anything else nothing happens.
                  I know nothing of css though and as such cant tell why.
                  Last edited by Kumagoro; Oct 21, 2006, 01:41 PM.

                  Comment

                  Working...
                  X