2

Here is my JS fiddle: https://jsfiddle.net/apasric4/1e2uyorv/

This is the section of my code that's causing me issues:

const randomizeWord=(randomWord)=> {
  let arr=randomWord.split("")
  for (let i=arr.length<0; i>0;i--) {
    let temp = arr[i];
    let j = Math.floor(Math.random() * (i + 1));
    arr[i] = arr[j];
    arr[j] = temp;
  }
  console.log(arr)
} 

I am following an instructional on creating a scrambling game. However for some reason, the array returned back to me is not scrambled properly. I don't get why that is? I seem to be doing that exact same thing as other coders are doing, but it's coming back to me the same way.

As you can see in the JS fiddle, its returning back undefined.

This is def a beginner question, but if someone could help I would really appreciate it.

Thanks

Bob
  • 117
  • 6
  • 5
    `arr.length<0` is a comparison. It return true or false (in this case, it is problably always false) and that value is assigned to `i`. Is that what do you want? – Amadeus Sep 16 '19 at 00:43
  • 2
    Your randomize function doesn't return anything, so your output is always `undefined` – Code Maniac Sep 16 '19 at 01:01

0 Answers0