views:

110

answers:

3

Implement the “Word Decoder” game. This game will present the player with a series of scrambled words (up to 20 words) and challenge him/her to attempt to unscramble them. Each time a new word is displayed, and a text input is provided for the user to write the unscrambled word. Once the player thinks the word has been properly decoded, he clicks on the “Check answer” button. If the player’s answer is correct, his score is increased by one. If his answer is not correct, he is notified and he is then given a different word.

i understood the Question , but i dont know how to generate it , or even how to start it!! any help please?

A: 

Look into loading a dictionary via XHR.
there are tons of those available online [http://www.mieliestronk.com/wordlist.html NOTE: it contains some swear words, if you're going to be doing this for academic purposes, since its your homework, you should look for a "clean" list]...

For scrambling the word: make your string into a char array, then find an array shuffle function [they are simple to write, I wrote one for my implementation of Bogosort]...

function shuffle(b)
{
    var a = b.concat([]); //makes a copy of B, b won't be changed...
    var final = [];
    while(a.length != 0)
    {
        //0 -> a length-1
        var targIndex = Math.round((a.length-1)*(Math.random()));
        var value = a[targIndex]
        a.remove(targIndex);
        final.push(value);
    }
    return final;
}

When the user is done inputting, simply compare input with the answer [case insensitive, ignore spaces] As stated in comments, there are also the possibility of anagrams, so be sure to check for those... perhaps, you could simply verify the word exists in the dictionary.

ItzWarty
got it!! , thank you, your idea is a bit like the Question idea chek out my code .. it's is not correct, but at least i start with it. if you have any idea how to modify it ,, that will be very helpful
Alaya
+1  A: 

To start, try breaking down the problem into things you'll need; think nouns and verbs. This is simply rewriting the problem in new terms. You need:

  • word: just a string, but it's a noun you'll need, so list it.
  • dictionary: a collection of words to choose from (during testing, you don't need many)
  • display: these become HTML elements, since you're working with JS
    • scrambled word
    • text input
    • submit button to check answer
    • score
    • "wrong answer" notifier
  • to scramble a word
  • to compare words: how can you compare two words to see if one is a permutation of the other? Do it right and anagrams aren't a problem.
  • to check an answer
  • to increment score
  • to notify user of incorrect answer
  • to present a new scrambled word

Any item beginning with "to" is a verb; anything else is a noun. Nouns become objects, verbs become methods/functions.

The above is mostly a top-down approach, in contrast with bottom-up (note that top-down vs bottom-up isn't an either-or proposition). Other approaches that might help with not knowing where to start are test driven development or its offshoot, behavior driven development. With these you start by defining, in code, what the program should do, then fill in the details to make it do that.

A hint on comparing words: the problem is basically defining an equivalence class—two strings are equivalent if one is a permutation of the other. The permutations of a string, taken together, form the equivalence class for that string; two strings are in the same equivalence class if the strings are equivalent. As the linked document points out, equivalence classes are well represented by picking a single element of the class as the class representative. Lastly, you can turn the equivalence class definition around: two strings are permutations of each other if they are in the same equivalence class.

outis
:D thanx alot .. i appreciate it .. i went along with your tips and explanationgod bless you
Alaya
A: 

This what i get from you guys! i generate another code ,, but it's not write im trying to figure out the right solution..

Assignment 1 : Task 3

    <script type="text/javascript">

        function check()
        {


            var correctArray = new Array ("cat", "car");
            correctArray[0]= 0;

            var wrong = new Array("tac", "rac");
            var score = 0;

            if( correctArray().index.length == wrong().index.length){
                alert("This is correct:" , correctArray());

            }else{

                alert(" please try again ");
            }
               return correctArray++, score++;
        }

    </script>


</head>
<body>


    <form>
        <h3> Words Decoder  </h3>

        The scrambled word is: <input type="text" name="showlabel" value="" disabled="disabled" onclick='check().getElementById("wrong")' />  <br/><br/>

        Please enter the unscrambeld word: <input type="text" name="userInput" value="" />

        <input type="submit" value="Check" onclick="check()" /><br/><br/>
        The Score is : <input type="text" name="score" value="" disabled="disabled" /><br/><br/>



    </form>


</body>

it should be like for example:

The word “tac” is displayed. The user inputs “cat”. The answer is correct, and the user’s score is 1. The word “niol” is then displayed. The user inputs “oinl”. The answer is not correct, the user is alerted, and the score stays the same. The game then displays the next word and so on. After the last word, the final score is given to the player.

Alaya
outis
If you haven't already, read the SO FAQs (http://stackoverflow.com/faq) and lurk a little to get used to how SO is structured. You also should read http://catb.org/~esr/faqs/smart-questions.html for tips on effectively asking questions.
outis
Ok. Thank you for your help. i will read it them .
Alaya