Jump to content


  • Posts

  • Joined

  • Last visited

DocGrimwig's Achievements


Newbie (1/7)



  1. dsonesuk...What an incredible gift you have given me. Thank you. I know that all of your Moderating takes up a great deal of time an effort, and so I want to say how appreciative I am of the time spent educating me. This was undoubtedly the best teaching on the web! I'm glad to say...I"VE GOT IT!!! -Doc
  2. Wow. This is so readable and helps me immensely to understand the flow. Thanks, Dave. dsonesuk, I'm not saying yours isn't, but I am saying that I am so new to this stuff, that your explanation goes right over the top of my head. I'm just barely above the level of "See Spot run. Run Spot run " (A children's book in case you're not from a country or a time when this book was in use teaching children to read :-) Dave and ds, for the sake of my education, is there not a simpler way than having to break the script down into 3 functions? For example, is it possible to include init and run within createString? Thanks so much both of you!!!! Doc
  3. So once I have targetted the userInput.value, how do I get it into the parameters for createString if not through a var like n?
  4. Oops. I didn't finish my thought... Instead of hard-coding an input and outputting to the console, I am trying to pass the value of an input to the function and then output it using .innerHTML.
  5. Hello: Below I successfully created a random string generator in js. As you can see, to verify it worked,I logged the output to the console. Now I have tried for hours to do something I thought was incredibly easy, and it probably would be if it weren't I trying to author it :-0 Commented out is the latest of my attempts to do so. The live code works correctly. <!doctype html><html><head><meta charset="utf-8"><title>Random String</title></head><body><!-- <h3>Please input a number to represent how long of a string you wish to randomly create</h3><input name= "userInput" id="userInput" maxlength="2"><button type="submit" onClick="createString()">Submit</button> <p id="output"></p>--><script>//Create function that will produce a random string from a supplied set of characters.function createString(n) { //Declare String Variable.var text = "";// n = [];//List of characters to be drawn fromvar char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; //Loopfor(var i=0; i < n; i++ ) { text += char_list.charAt(Math.floor(Math.random() * char_list.length)); } //Return the value of the function to the var "test"return text; } //Display the value of the returned random string to the console. Call the function with a parameter n of 10console.log(createString(10)); //document.getElementById("output").innerHTML= createString();</script></body></html> Can you help! Thanks so much, Doc
  6. In the following code: <codeblock> <script> $(document).ready(function(){ $("#hide").click(function(){ $("img").hide(); }); $("#show").click(function(){ $("img").show(); }); }); </script> </codeblock> Is my method and syntax correct for hiding an <img>? Thanks, Doc
  7. justsomeguy: Unfortunately when I click the button it does nothing. There are no syntax errors so I don;t know what it is. It looks right... Doc
  8. So here is my program to take a user input, process it for all possible word combinations and then output the resulting string array to a p string I have been working on this for weeks and was sure I had finally gotten it. Can anyone help? Thanks! Doc <codeblock> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Word Combinations</title> </head> <body> <h3>Please input a word to be processed for all of its possible combinations:</h3> <input id="userInput" type="text" autofocus="autofocus"> <button id="processInput" onClick="getAnagrams("userInput")">Process</button> <p id="returnValue"></p> <script> function swap(chars, i, j) { var tmp = chars; chars = chars[j]; chars[j] = tmp; } function getAnagrams(input) { //initialize the variables var counter = [], anagrams = [], chars = input.split(''), length = chars.length, i; //determine how many letters are in the string for (i = 0; i < length; i++) { counter = 0; } // for loop 1st it will set i to 0; then if i < 3 (using Dog); increment by 1's //next loop sets i to 1; i is still less than 3; so increment by 1 again //next loop sets i to 2; i is still less than 3; so increment by one again //next loop sets i to 3; i is NO LONGER less than 3 so loop stops and returns a string length of 3 (0,1,2 = 3 in the array) //push the original string in container anagrams.push(input); //the (input) string 'dog' is put into the anagrams container //start from first letter i = 0; while (i < length) { if (counter < i) { // i is now = to 0 in the array = 'd' // WHILE i < 3 and IF the loop counter is less than 3 then perform the following //swap the two letters in questions swap(chars, i % 2 === 1 ? counter : 0, i); //increment counter counter++; i = 0; //push new combination into container anagrams.push(chars.join('')); } else { counter = 0; //increment counter i++; } } //return string of results // return anagrams; //Place the result of anagrams into the p id = "returnValue" document.getElementById("returnValue").innerHTML = anagrams; } </script> </body> </html> </codeblock>
  9. Thanks. It is such a big mtn to climb. Thanks for your help. Any opinion on should I learn something like Angular.js to bootstrap etc? And if so, before I do .js or after?
  10. I understood permutations to mean: d, o, g, do, od, dg, gd.....dog, dgo, odg ect... So what is the above??
  11. I'm so new to this. I'm an idiot "justsomeguy." I don;t need recursion after all, I am thinking incorrectly. I just need to get it accomplished. I feel stupid.
  12. I have been trying to apply the theory of recursion to practical application within a JS function. At first I thought it would be easy. I have found several attempts, but most are all over the place and it's hard to follow them and to learn something from them. I have spent days with others, only to discover they are not using proper JS protocols. Can anyone link me to a GREAT Word Combination (recursive, repeating) -permutations, JS function that finds all of the combinations of an input word and displays them in the browser? I am so new that I can't tell what's good or what's bad. Thanks! Doc
  13. I am totally new to programming and am trying to adapt a snippet that was written to the console so that it now takes a user input and outputs to the browser. I have searched w3schools and other helps, but can't seem to get this last bit done. I don;t have any syntax issues apparently, and haven't earned to debug yet, so I've hit a wall. Can you help? <codebox> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Possible Word Combinations</title> </head> <body> <h4>Please input a word below</h4> <input type="text" id="userInput" > <button onclick="scramble()">Submit</button> <p id="inputValue"></p> <script> function scramble(word) { var word = document.getElementById("UserInput") var words = [], rearrangedWord, head, tail; if (!word) { return words; } function rearrange(str, prefix) { prefix = prefix || ''; str.split('').map(function(head, idx) { tail = str.slice(0, idx) + str.slice(idx + 1); rearrangedWord = prefix + head + tail; if (words.indexOf(rearrangedWord) < 0) { words.push(rearrangedWord); } if (tail.length > 1) { rearrange(tail, prefix + head); } }); } rearrange(word, ''); return words; } document.getElementById("inputValue").innerHTML = words; (scramble("userInput")); </script> </body> </html> </codebox>
  • Create New...