-6
Var randomLetters = "ljhgfdza";
Var randomString = "";

Now I'll have to add elements in the first variable to the second Randomly Using the while loop, and Math.floor(Math.random() * random letters.length)

I am having a problem at my "While (condition)" what should it be?

Colwin
  • 2,655
  • 3
  • 25
  • 25
neth99
  • 3
  • 1
  • 2
    show us what you have. We aren't going to just code the solution for you. Edit your question to include your code. – SaggingRufus May 24 '17 at 11:05
  • We can't know what the requirements are. Do you have to keep adding until the strings have the same length? Some fixed length? Until all characters are used? Some other condition? – JJJ May 24 '17 at 11:05

2 Answers2

0

To flat out answer your question, you can use:

while(randomLetters.length > 0){

Then when you use a letter from randomLetters, you delete the letter and the length is now 1 less.

Matt
  • 1,062
  • 1
  • 8
  • 11
-1

This will be enough for you:

const randomLetters = "ljhgfdza";
const returnRandom = (randomString) => {
  const arrString = [...randomString].sort((a, b) =>{
    return 0.5 - Math.random()
  }).join("");
  console.log(typeof arrString,arrString);
}
returnRandom(randomLetters);

but... in this case sort method is not that random as you think. This link will tell you why. I would do this with reduce() or map(), both are described in link above.

NightKn8
  • 379
  • 6
  • 18
  • Please explain why I was downvoted so I can improve my answer. – NightKn8 May 24 '17 at 12:45
  • please review this code u'll understand var i = ""; var x = "ghtyvbnm"; while (x.length < 6) { console.log(x += i); Math.floor(Math.random() * x.length); } – neth99 May 24 '17 at 21:55