and what is it looking at? i really cant get it
what are the other functions you have created? is there one that selects a random question object?
yess?
function getRandomQuestion(questions){
let randomNum = Math.floor(Math.random()*questions.length)
return questions[randomNum]
isnt this one ?
so you can get a question object from something, you can use the output of that function as first argument of getRestults
I redid it, but something is still incorrect.
In console i have :
// running tests
// tests completed
// console output
{ category: ‘Pca’,
question: ‘fav car?’,
choices: [ ‘Toyota’, ‘Lambo’, ‘BMW’ ],
answer: ‘BMW’ }
Yellow
The computer’s choice is correct!
my console.logs are:
console.log(getRandomQuestion(questions));
console.log(getRandomComputerChoice([ 'Red', 'Blue', 'Yellow' ]));
console.log(getResults(getRandomQuestion(questions), 'Red'));
what do you think is incorrect here?
my only option, is that i have a constant ‘red’ choice in getResults function. Is the issue? If yes, i definetely should replace it, but i have no idea with what..
instead of logging this, store the chosen question object in a variable, and use that variable to get the arguments of the other functions
let randQ = getRandomQuestion(questions)
console.log(getRandomComputerChoice([ 'Red', 'Blue', 'Yellow' ]));
console.log(getResults(randQ, 'Red'));
do you mean like that? i just canceled out the console.log you replied to.
for the first line, yes, for the other two, you need more work
from the question object, how do you get the list of possible answers? you need to pass that to getRandomComputerChoice
, you also need to save the result as you need it for getResults
for getResults
, the first argument is correct, but the second one needs to come from getRandomComputerChoice
let randQ = getRandomQuestion(questions)
let answers = randQ.choices
console.log(getRandomComputerChoice(answers));
let choiceForResults = getRandomComputerChoice(answers)
console.log(getResults(randQ, choiceForResults));
Tried like that, the test is still passing, but the code doesnt work properly.
my console :
Hustling
The computer’s choice is correct!
instead of doing this, you may want to remove the first console.log and instead do console.log(choiceForResults)
what do you expect to see in the console? why do you say it is not working properly?
oh yes, no i see that it works correctly, thank you so much!
and i am sorry that i took me a while to reply several times!