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) { return (

Please wait..

) } // This is an experimental JavaScript feature where we can get with // using babel-preset-stage-0 const message = do { if (randomNo < 30) { 'Do not give up. Try again.' } else if (randomNo < 60) { 'You are a lucky guy' } else { 'You are soooo lucky!' } } return (

Your Lucky number is: "{randomNo}"

{message}

) } }