0

I want to pass a random company name with only letters, no numbers and special characters. I used the function below but it is passing alphanumeric and special characters to the company name value. Is this the correct function to use?

function generateNewCompanyName() 
   {
   let text="";
   let alphabet="abcdefghijklmnopqrstuvwxyz"
   for(let i=0; i<10; i++)
   text +=alphabet.charAt(Math.floor(Math.random()*alphabet.length))
   return text;
   }
   Cypress.config('generatedCompanyName',Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15))
Peter O.
  • 32,158
  • 14
  • 82
  • 96
user15591439
  • 1
  • 1
  • 1
  • 2
  • 1
    Does this answer your question? [Generate random string/characters in JavaScript](https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript) – Sudhir Ojha Apr 09 '21 at 12:17
  • Your function is fine, the problem is apparently on the `Cypress.config` line – georg Apr 09 '21 at 12:19
  • 1
    Where do you actually use the `generateNewCompanyName` function? How about `Cypress.config('generatedCompanyName', generateNewCompanyName());`? – Đinh Carabus Apr 09 '21 at 13:27
  • Changing this has resolved the issue Cypress.config('generatedCompanyName', generateNewCompanyName()); Thanks. – user15591439 Apr 12 '21 at 00:36

0 Answers0