let questions=[
{
category:"color? ",
question:"what is your favorite color?",
choices:["blue","pink","green"],
answer:"green",
},
{
category:"living place?",
question:"where are you living there ?",
choices:["Bursa","Ankara","Istanbul"],
answer:"Istanbul",
},
{
category:"Field of study?",
question:"Do you grageuated?",
choices:["computer","Math","teacher"],
answer:"computer",
},
{
category:"cooking?",
question:"What is your favorite food?",
choices:["Pizza","Ege","Rice"],
answer:"Ege",
},
{
category:"sports?",
question:"What is your favorite sport?",
choices:["football", "volleyball","swimming"],
answer:"volleyball",
}
];
function getRandomQuestion(questions) {
let randomQuestion = Math.floor(Math.random() * questions.length);
return questions[randomQuestion];
};
//FUNCTION CALL
let gRandomQuestion = getRandomQuestion(questions);
function getRandomComputerChoice(gRandomQuestion) {
let random = Math.floor(Math.random() * gRandomQuestion.length);
return gRandomQuestion[random];
};
//FUNCTION CALL
let computerChoice = getRandomComputerChoice(gRandomQuestion.choices);
//console.log(computerChoice);
let rightAnswer = gRandomQuestion.answer;
//console.log(rightAnswer);
function getResults(pcChoice,truAnswer) {
return pcChoice == truAnswer? "The computer's choice is correct!" : `The computer's choice is wrong. The correct answer is: ${truAnswer}`
};
console.log(getResults(computerChoice,rightAnswer));
my program work , but the test 11 and 12 not passed. please help what is the problem
function getResults(pcChoice,answer) {
return pcChoice == answer? "The computer's choice is correct!" : `The computer's choice is wrong. The correct answer is: ${answer}`};
//FUNCTION CALL
let gRandomQuestion = getRandomQuestion(questions);
let computerChoice = getRandomComputerChoice(gRandomQuestion.choices);
let result=getResults(computerChoice,gRandomQuestion.answer);
console.log(result);
the answer property. if we send the question object us argument of getResults function i edited the code us bellow. but stil not passed.
function getResults(pcChoice,gRandomQuestion) {
let answer=gRandomQuestion.answer;
return pcChoice == answer? "The computer's choice is correct!" : `The computer's choice is wrong. The correct answer is: ${answer}`};
//FUNCTION CALL
let gRandomQuestion = getRandomQuestion(questions);
let computerChoice = getRandomComputerChoice(gRandomQuestion.choices);
let result=getResults(computerChoice,gRandomQuestion);
console.log(result);
let questions=[
{
category:"color? ",
question:"what is your favorite color?",
choices:["blue","pink","green"],
answer:"green",
},
{
category:"living place?",
question:"where are you living?",
choices:["Bursa","Ankara","Istanbul"],
answer:"Istanbul",
},
{
category:"Field of study?",
question:"Do you grageuated?",
choices:["computer","Math","teacher"],
answer:"computer",
},
{
category:"cooking?",
question:"What is your favorite food?",
choices:["Pizza","Ege","Rice"],
answer:"Ege",
},
{
category:"sports?",
question:"What is your favorite sport?",
choices:["football", "volleyball","swimming"],
answer:"volleyball",
}
];
function getRandomQuestion(questions) {
let randomQuestionObj = Math.floor(Math.random() * questions.length);
return questions[randomQuestionObj];
};
function getRandomComputerChoice(gRandomQuestion) {
let random = Math.floor(Math.random() *gRandomQuestion.length);
return gRandomQuestion[random];
};
function getResults(pcChoice,gRandomQuestion) {
let answer=gRandomQuestion.answer;
return pcChoice == answer? "The computer's choice is correct!" : `The computer's choice is wrong. The correct answer is: ${answer}`};
//FUNCTION CALL
let gRandomQuestion = getRandomQuestion(questions);
let computerChoice = getRandomComputerChoice(gRandomQuestion.choices);
let result=getResults(computerChoice,gRandomQuestion);
console.log(result);
Please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.
The easiest way to create a topic for help with your own solution is to click the Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.