What I have to do
Create a program that asks a user for a word of any length. Then randomly generate a new word of the same length using only the letters of the first word. Use any letter any number of times. Ensure you capitalize only the first letter of the new word. NOTE. If there is a space in the user word, then you’ll have a space in your output. Capitalize each word. Example:
User Word : Dogma
Randomly generated word might be Gogoa or Oogma or Gmado notice, only in the last example did I actually use each letter exactly once.
You must: Use an array, a loop, conditional, function (other than onclick), your code must start with Onclick. Use all BP’s.
Algorithm:
determine the length of the word.
- slice the word into an array of letters…. use a loop
- randomly generate a number between 1 and the length of the word
- assemble the new word, capitalize the first letter, ensure others are lowercase.
- repeat 3 and 4
- display new word.
(me)
So I have a text box and i used word length to get the amount of letters in that word. Then I have a repeating for loop to get the array from the word and I made a random number. How would I turn this stiff into letters and scramble it? I know it isn't nearly done I just want some tips.
<html>
<head>
<title>Final</title>
</head>
<body>
<h1>Final</h1>
Random Word generator <br>
<input type="text" id="word">
<input type="button" id="submit" value="Randomize" onclick="Random()">
<script language="javascript">
word = document.getElementById("word").value
var n = word.length;
function Random(){
for(start = 0; start < n; start++){
Array.from(word)
do{
var x = Math.round((Math.random() * n) + 1);
function capitalize(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
}
while{
x != n;
}
document.getElementById("word").value = (capitalize(word));
}
</script>
</body>
</html>