Its in reference to this point: You should have a function named getRandomComputerChoice that takes the array of the available choices as a parameter, and returns a random answer to the selected question.
Choices are in array so will it not worrk like this?
What is the “array of available choices” and where is it?
You need to use the choices parameter in your function. You never use it.
You need to write the function assuming that the “array of available choices” has been passed as an argument to your function, and access it by the choices parameter.
Have updated first two functions and it start giving new questions and new available choices not but should the choices should be corresponding to question , as it shows diff questions and different choices from other question.
I am so confused if you could tell me what is end product so I can work accordingly as to me we should have question showing available choices to pick and in result function we should give one choice which should be matched against correct answer. here my two updated function below and will work on get result one once it work correctly. Second function showing choiceds without me putting any argument when I call function.
//FUNCTION ONE QUESTION
function getRandomQuestion (questions)
{
let randomNum = Math.floor(Math.random() * questions.length);
let randomQ=questions[randomNum].question;
console.log(`Random question: ${randomQ}.`)
return randomQ;
}
getRandomQuestion(questions);
//FUNCTION TWO CHOICE
function getRandomComputerChoice (choice)
{
let randomNum = Math.floor(Math.random() * questions.length);
let randomCh=questions[randomNum].choices;
console.log(`Random choice: ${randomCh}.`)
return randomCh;
}
getRandomComputerChoice ();
You should have a function named getRandomQuestion that takes an array of questions as a parameter and returns a random question object from the array.
What does this user story say you should return from getRandomQuestion?
No. You are returning the question in the question object. You should be returning the entire question object. Then you can use that question object to get the choices to pass to getRandomComputerChoice. Make sense?
can it be more simplify sorry but its so confusing ….getting entire object means gettting all as in ..choices, answers, catagory etc. not only one question from that one object.
The questions array is an array of question objects, right?
Pretend that you write all of the stuff in each question object on a piece of paper, mix up all those papers in a pile, and pick one. Now you have a piece of paper with the category, question, choice, and answer for one randomly selected question object. Next you write down each choice from that specific question object on a piece of paper, mix them up in a pile, and pick one. Now you have a randomly selected choice from that question object, which, in this case, represents the computer choice. Because you are passing the entire question object to getResults, you can access the answer and compare that to the computer choice.
Good job on the getRandomQuestion changes! Please read the edit to my last post to help you understand how to use that result to get the choices to pass to getRandomComputerChoice.