Write a JavaScript function that extracts a random character

Write a JavaScript function that extracts a random character from a given string without using .charAt or a local index variable.

Solution

function printS(x){
   rand = Math.floor((Math.random() * x.length) + 1); //generating a random variable from 1 to length of the given string
return x[rand]; //returning a character which is at the random location. This can be done without using charAt or indexOf functions
}

Write a JavaScript function that extracts a random character from a given string without using .charAt or a local index variable.Solutionfunction printS(x){ ran

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site