Created
August 29, 2018 04:23
-
-
Save nupurndas/6f4cafe2e94d44417fbfca579eea4b89 to your computer and use it in GitHub Desktop.
onclick not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import './index.css'; | |
import AutherQuiz from './AutherQuiz'; | |
import registerServiceWorker from './registerServiceWorker'; | |
import {shuffle,sample} from 'underscore'; | |
const authors = [ | |
{ | |
name:"Mark Twain", | |
imageUrl: "images/marktwain.jpg", | |
books: ['Adventures of Huckelberry Fin','Twilight','Ghost of the White House'] | |
}, | |
{ | |
name:"Thomas Hardy", | |
imageUrl: "images/thomashardy.jpg", | |
books: ['Mayor of CasterBridge','ABC','DEF'] | |
}, | |
{ | |
name:"J K Rolling", | |
imageUrl: "images/jkrolling.jpg", | |
books: ['Harry Potter','IFK','CBC'] | |
}, | |
{ | |
name:"Salman Rushdie", | |
imageUrl: "images/salmanrushdie.jpg", | |
books: ['Midnight children dream ','Twilight','Error of Human Mind'] | |
}, | |
{ | |
name:"Arundhati Roy", | |
imageUrl: "images/arundhatiroy.jpg", | |
books: ['God of Small Things','No small being','I love nothing'] | |
}, | |
]; | |
function getturndata(authors) | |
{ | |
const allBooks = authors.reduce(function(p,c,i){ | |
return p.concat(c.books); | |
},[]); | |
const fourRandomBooks = shuffle(allBooks).slice(0,4); | |
const answer = sample(fourRandomBooks); | |
return{ | |
books: fourRandomBooks, | |
author: authors.find((auther) => | |
auther.books.some((title) => title === answer) | |
) | |
} | |
} | |
const state = { | |
turnData: getturndata(authors), | |
highlight:'' | |
}; | |
function onAnswerSelected(answer){ | |
console.log(answer); | |
//const isCorrect = state.turnData.author.books.some((book) => book === answer); | |
const isCorrect = true; | |
state.highlight = isCorrect ? 'green' : 'red'; | |
render(); | |
} | |
function render(){ | |
ReactDOM.render(<AutherQuiz data={state} onAnswerSelected={onAnswerSelected} />, document.getElementById('root')); | |
} | |
render(); | |
registerServiceWorker(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment