Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

math.random code not working with arrow function

shuffledQuestions=questions.sort=>(Math.random() -0.5)

can someone help please

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to pass in a function to Array::sort

The correct format for arrow functions is () => {}

const questions = ['What is your name?', 'What is your quest?', 'What is your favorite color?'];

//shuffle the array
questions.sort(() => Math.random() - 0.5);
console.table(questions);

You can learn more about arrow functions here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading