2016-12-22 01:36:00 +00:00
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
export default class MyLuckNo extends React.Component {
|
|
|
|
constructor (...args) {
|
|
|
|
super(...args)
|
|
|
|
this.state = { randomNo: null }
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.recalculate()
|
|
|
|
}
|
|
|
|
|
|
|
|
recalculate () {
|
|
|
|
this.setState({
|
|
|
|
randomNo: Math.ceil(Math.random() * 100)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { randomNo } = this.state
|
|
|
|
|
|
|
|
if (randomNo === null) {
|
2018-12-17 16:34:32 +00:00
|
|
|
return <p>Please wait..</p>
|
2016-12-22 01:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is an experimental JavaScript feature where we can get with
|
|
|
|
// using babel-preset-stage-0
|
|
|
|
const message = do {
|
|
|
|
if (randomNo < 30) {
|
2017-03-03 00:17:41 +00:00
|
|
|
// eslint-disable-next-line no-unused-expressions
|
2018-12-17 16:34:32 +00:00
|
|
|
;('Do not give up. Try again.')
|
2016-12-22 01:36:00 +00:00
|
|
|
} else if (randomNo < 60) {
|
2017-03-03 00:17:41 +00:00
|
|
|
// eslint-disable-next-line no-unused-expressions
|
2018-12-17 16:34:32 +00:00
|
|
|
;('You are a lucky guy')
|
2016-12-22 01:36:00 +00:00
|
|
|
} else {
|
2017-03-03 00:17:41 +00:00
|
|
|
// eslint-disable-next-line no-unused-expressions
|
2018-12-17 16:34:32 +00:00
|
|
|
;('You are soooo lucky!')
|
2016-12-22 01:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h3>Your Lucky number is: "{randomNo}"</h3>
|
|
|
|
<p>{message}</p>
|
|
|
|
<button onClick={() => this.recalculate()}>Try Again</button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|