@@ -3,7 +3,6 @@ import ReactDOM from 'react-dom';
3
3
//import PropTypes from 'prop-types';
4
4
5
5
function shuffleArray ( array ) {
6
- //if(typeof array !== 'object') return;
7
6
let i = array . length - 1 ;
8
7
for ( ; i > 0 ; i -- ) {
9
8
const j = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
@@ -16,78 +15,129 @@ function shuffleArray(array) {
16
15
class Quiz extends React . Component {
17
16
constructor ( props , context ) {
18
17
super ( props , context ) ;
19
-
18
+ this . refreshQuestion = this . refreshQuestion . bind ( this )
19
+ this . state = {
20
+ change :false
21
+ }
22
+ }
23
+ refreshQuestion ( ) {
24
+ console . log ( this ) ;
25
+ this . setState ( {
26
+ change :true
27
+ } )
20
28
}
21
29
render ( ) {
22
30
var shuffledPosts = shuffleArray ( this . props . data ) ;
23
- console . log ( shuffledPosts [ 0 ] ) ;
24
31
return < div >
25
- < div className = "row" >
32
+ < div className = "row posRelative " >
26
33
< div className = "col-md-10" >
27
- < Question data = { shuffledPosts [ 0 ] . question } />
28
-
29
-
30
- < Options data = { shuffleArray ( shuffledPosts [ 0 ] . options ) } />
34
+ < Question data = { shuffledPosts [ 0 ] . question } />
31
35
</ div >
32
- < div className = "col-md-2" >
36
+ < Options data = { ( shuffledPosts [ 0 ] ) } />
37
+
33
38
34
- </ div >
39
+ </ div >
40
+ < div className = "col-md-10 noPadRight" >
41
+ < button onClick = { this . refreshQuestion } className = "marTop25 nextBtn btn col-md-2 pull-right" > Next Question</ button >
35
42
</ div >
36
43
</ div > ;
37
44
}
38
45
}
39
46
class Question extends React . Component {
40
47
render ( ) {
41
- //shuffledPosts[0].answer is the answer
42
48
return < div className = "lead question" >
43
49
< h3 > { this . props . data } </ h3 >
44
50
</ div >
45
51
}
46
52
}
47
53
48
54
class Options extends React . Component {
55
+ constructor ( props ) {
56
+ super ( props )
57
+ this . state = {
58
+ bgClass :'neutral'
59
+ }
60
+ }
61
+ handleClick ( valClicked ) {
62
+ var isCorrect = valClicked . value === this . props . data . key ;
63
+ this . setState ( {
64
+ bgClass : isCorrect ? 'pass' : 'fail' ,
65
+ showContinue : isCorrect
66
+ } )
67
+ }
68
+ componentWillReceiveProps ( nextProps ) {
69
+ this . setState ( {
70
+ bgClass : 'neutral'
71
+ } )
72
+ }
49
73
render ( ) {
50
- //console.log(this.props.data)
51
- // return <div className="option">
52
- // <h4>{this.props.data}</h4>
53
- // </div>
54
-
55
- var options = this . props . data ;
74
+ var options = this . props . data . options ;
56
75
return (
57
76
< div >
58
- { options . map ( function ( value , index ) {
59
- console . log ( index )
60
- return < div className = "strong options" key = { index } >
61
- < h4 > { index + 1 } . { value } </ h4 >
62
- </ div > ;
63
- } ) }
77
+ < div className = "col-md-10" >
78
+ { options . map ( ( value , index ) => {
79
+ return < div onClick = { this . handleClick . bind ( this , { value} ) } className = "strong options" key = { index } >
80
+ < h4 > { index + 1 } . { value } </ h4 >
81
+ </ div > ;
82
+ } , this ) }
83
+ </ div >
84
+ < Answer className = { this . state . bgClass } />
64
85
</ div >
65
86
)
66
87
}
67
88
}
68
89
69
- // Quiz.PropTypes = {
70
- // books: PropTypes.bool.isRequired,
71
- // }
72
- // Book.PropTypes = {
73
- // b: PropTypes.string
74
- // }
90
+ class Answer extends React . Component {
91
+ // constructor(props){
92
+ // super(props);
93
+ // }
94
+ render ( ) {
95
+ return < div className = { this . props . className + ' col-md-1' } > </ div >
96
+ }
97
+
98
+ }
75
99
76
100
var data = [
77
101
{
78
102
question : "What is the Javscript compiler name in Google Chrome?" ,
79
- options : [ "Chrome V8 " , "Chrome V7" , "Chrome V9" , "Chrome V6 " ] ,
80
- answer : "Chrome V8"
103
+ options : [ "Chrome V6 " , "Chrome V7" , "Chrome V8" , "Chrome V9 " ] ,
104
+ key : "Chrome V8"
81
105
} ,
82
106
{
83
107
question : "How can you detect the client's browser name?" ,
84
108
options : [ "navigator.userAgent" , "navigator.browser" , "browser.appName" , "app.browserName" ] ,
85
- answer : "I am answer 2 "
109
+ key : "navigator.userAgent "
86
110
} ,
87
111
{
88
112
question : "Nearly all objects in JavaScript are instances of which of the following?" ,
89
113
options : [ "Object" , "_proto_" , "Prototypes" , "DOM" ] ,
90
- answer : "I am answer 3"
114
+ key : "Object"
115
+ } ,
116
+ {
117
+ question : "Which of the following is a correct way to empty an array?" ,
118
+ options : [ "arrayName.empty();" , "arrayName.splice(0, arrayList.length);" , "arrayName = null;" , "arrayName = Obejct.empty();" ] ,
119
+ key : "arrayName.splice(0, arrayList.length);"
120
+ } ,
121
+ {
122
+ question : "Which of the following is not a React Component Lifecycle method?" ,
123
+ options : [ "componentWillUpdate " , "componentDidUpdate " , "componentWillUnmount " , "componentGoingToUpdate" ] ,
124
+ key : "componentGoingToUpdate"
125
+ } ,
126
+ {
127
+ question : "In Experience Technology world, What does MEAN stand for?" ,
128
+ options : [ "Mongodb, ES6, Angularjs and Node" ,
129
+ "Mongodb, Ember, Angularjs and Node" ,
130
+ "Mongodb, Express, Angularjs and Node" ,
131
+ "Meteor, Express, Angularjs and Node" ] ,
132
+ key : "Mongodb, Express, Angularjs and Node"
91
133
}
92
134
]
135
+
136
+ // Quiz.PropTypes = {
137
+ // books: PropTypes.bool.isRequired,
138
+ // }
139
+ // Book.PropTypes = {
140
+ // b: PropTypes.string
141
+ // }
142
+
93
143
ReactDOM . render ( < Quiz data = { data } /> , document . getElementById ( 'root' ) ) ;
0 commit comments