Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: say("HELLO");

  1. #1
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default say("HELLO");

    A simple say("hi") reply("hi to you") type of script. Note that it is JavaScript.

    Code:
    function say(word)
    {
    if(word == "S---") reply("How dare you use such word!");
    else if(word == "F---") reply("You could just say \"Whoops!\"!");
    else if(word == "Maam, you dropped that anvil on your toe.") say("S---");
    else if(word == "Did you remeber to mail the gas bill?") say("F---");
    }
    
    function reply(word)
    {
    alert(word);
    }


    -magicyte

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    More efficient, hehe :

    Code:
    <script type="text/javascript">
      var words = {
        someword: "someword reply",
        hello: "how do you do",
        "how are you doing": "test"
      }, say = function(word) {
        for (var x in words) {
          if (word.toLowerCase() == x) {
            reply(words[x]);
          };
        };
      }, reply = function(word) {
        alert(word);
      };
      say("Hello");
    </script>
    - Mike

  3. #3
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Ha!

    -magicyte

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Actually that's less efficient (but neater, admittedly). for..in loops are very slow. Neater still, no guarantee of efficiency (but got to be better than the for..in):
    Code:
    var say = (function(words, v, say) {
      return say = function(sentence) {
        (v = words[(alert(sentence), sentence).toLowerCase()]) && say(v);
      };
    })({
      "s---" : "How dare you use such language!",
      "f---" : 'You could just say "Whoops!"',
      "ma'am, you dropped that anvil on your toe." : "S---",
      "did you remember to mail the gas bill?" : "F---"
    });
    Aren't you from America, Magicyte? Your English seems somewhat non-native...
    Last edited by Twey; 09-02-2008 at 01:52 AM. Reason: It's one function, why is there still a container?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by Twey View Post
    Aren't you from America, Magicyte? Your English seems somewhat non-native...
    Really? This is how everybody talks in America. How does it seem "non-native"?

    -magicyte

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Wow that was really stupid of me :/ ... I'm not thinking right. I didn't think of the simple fact that you could call the value of the array with the argument in the function haha.
    - Mike

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Things like "how dare you use such word" remind me of Engrish
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I think that's pretty commonly used though... But my perspective probably isn't the greatest, considering all the different accents that are around here.
    - Mike

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    But 'word' is a singular countable, and 'such' expects a plural or uncountable.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    I would say, "How dare you use such a word."
    Trinithis

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •