SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2. import "./App.css";
  3.  
  4. class Board extends React.Component {
  5.   constructor() {
  6.     super();
  7.     this.state = {
  8.       digits: [1, 2, 4, 8],
  9.       date: new Date(),
  10.       binaryHoursDecimal: [false, false],
  11.       binaryHoursUnity: [false, false, false, false],
  12.  
  13.       binaryMinutesDescimal: [false, false, false],
  14.       binaryMinutesUnity: [false, false, false, false],
  15.  
  16.       binarySecondsDecimal: [false, false, false],
  17.       binarySecondsUnity: [false, false, false, false]
  18.     };
  19.   }
  20.  
  21.   refresh() {
  22.     this.setState({
  23.       date: new Date()
  24.     });
  25.   }
  26.  
  27.   componentDidMount() {
  28.     this.interval = setInterval(() => this.refresh(), 1000);
  29.     let i;
  30.     let rest;
  31.     let unity;
  32.     let hour = this.state.date.getHours();
  33.     let minutes = this.state.date.getMinutes();
  34.     let seconds = this.state.date.getSeconds();
  35.  
  36.     if (hour > 10) {
  37.       this.setState({
  38.         binaryHoursDecimal: [true, false]
  39.       });
  40.       unity = hour % 10;
  41.  
  42.       for (i = 3; i >= 0; i--) {
  43.         if (unity >= this.state.digits[i]) {
  44.           unity = unity / this.state.digits[i];
  45.           this.setState(prevState => {
  46.             binaryHoursUnity: prevState.binaryHoursUnity[i] = ``true;
  47.           });
  48.         }
  49.       }
  50.     } else {
  51.     }
  52.   }
  53.  
  54.   componentWillUnmount() {
  55.     clearInterval(this.interval);
  56.   }
  57.  
  58.   render() {
  59.     return <div> {console.log(this.state.binaryHoursUnity)} </div>;
  60.   }
  61. }
  62.  
  63. export default Board;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top