The program is supposed to tank the word you entered into a box split it into an array of letters and shuffle them. After that it capitalizes the first letter and lowercase the rest and outputs that into the same box.
I am trying to scramble a word into random letters but I can't get past this error.
In chrome it said I have an unexpected Identifier and in mozilla it said i am missing a bracket for newWord = shuffle(newWord); *fixed
Edit: now i have an error saying that that capitalize is not a function.
<html>
<head>
<title>Final</title>
</head>
<body>
<h1>Final</h1> Random Word scrambler
<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 (var start = 0; start < n; start++) {
var newWord = word.charAT(start)
newWord = shuffle(newWord);
function shuffle(array) {
var currentIndex = array.length,
temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
function capitalize(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
Array.join(newWord);
}
}
if (newWord == newWord){
document.getElementById("word").value = (capitalize(newWord));
}
}
</script>
</body>
</html>
var newWord = (word.charAT(start)
, you need to delete that first(
– hackerrdavecharAT
should becharAt
. – Scott Marcus