randomly changing color of tiles
index.js------------------
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('msg'));
App.js------------------
import React, {Component} from 'react';
// import NoteTakingApp from './components/noteTakingApp';
// import NoteTakingApp from './components/noteTakingApp';
import QuessWhat from './components/guessWhat';
import './assets/StyleApp.css';
class App extends Component {
render() {
return(
<div>
<QuessWhat />
</div>
);
}
}
export default App;
guessWhat.js-----------------
import React from 'react';
// import SingleTile from './tile';
import '../assets/StyleApp.css';
// class Pasting extends Component{
// render(){
// return(
// <>
// <div className='heading'>
// <div>
// <h1>Welcome! Guess What</h1>
// </div>
// </div>
// <div id="cards">
// <div className="firstCard">
// <SingleTile colorname="Red" isvalue ={true}/>
// </div>
// <div className="secondCard">
// <SingleTile colorname="Blue" isvalue ={true}/>
// </div>
// <div className="thirdCard">
// <SingleTile colorname="Green" isvalue ={false}/>
// </div>
// <div className="fourthCard">
// <SingleTile colorname="Yellow" isvalue ={true}/>
// </div>
// </div>
// </>
// );
// }
// }
// export default Pasting;
function SingleTile(){
const universalFunc=()=>{
const red = "#ff0000";
const blue = "#0000ff";
const green = "#6FFF00";
const yellow = "#ffff00";
const pink = "#ffc0cb";
//generate random number
const randomColorGenerated=()=>{
var random = Math.floor(Math.random() * 4) + 1;
//*4 means four numbers not multiplication.
console.log(random);
var newResult = pink;//initiallizing newResult
if (random === 1) {
console.log("first color");
return newResult=yellow;
}
if(random === 2){
console.log("second color");
return newResult=blue;
}
if(random === 3){
console.log("third color");
return newResult=red;
}
else {
console.log("fourth color");
return newResult=green;
}
}
const getVal = randomColorGenerated();
console.log("getval is "+ getVal);
return getVal;
}
const finalVal = universalFunc();
console.log("finalValue: "+finalVal);
const element = document.getElementById("msg");
element.style.background = finalVal;
setInterval(universalFunc, 1000);
return(
<div>
<div >
<p>Hello user!, Note the color of tile. Color Name:</p>
</div>
<button type="reset" onClick={SingleTile}>change</button>
</div>
)
}
export default SingleTile;
index.html-----------------------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="stylesheet" type="text/css"href="./src/assets/StyleApp.css">
<title>Profiler-Welcome</title>
<script src="https://cdn.ckeditor.com/4.14.1/standard/ckeditor.js"></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="msg">
<!-- <button id="heading" href="#">
Hey, How's you doin?
</button> -->
<button type="reset">Change</button>
</div>
</body>
</html>
styleApp.css----------------------------
*{
margin: 0px;
padding: 0xp;
/* padding-top: 20px; */
}
.tile{
background: red;
border: 4px solid black;
height: 250px;
width: 300px;
margin: auto auto;
border-radius: 8px;
color: rgb(248, 209, 175);
text-align: center;
font-size: 2rem;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
#cards{
width: fit-content;
height: fit-content;
margin: auto;
}
.firstCard{
background: orchid;
}
.firstCard p{
font-family: 'Times New Roman', Times, serif;
}
.demo{
background: darkmagenta;
}
.demo2{
background: gray;
}
#msg {
border: 4px solid black;
height: 110px;
width: 10%;
font-size: 20px;
margin: auto;
padding: 50px;
color: white;
font-family: verdana;
border-radius: 10px;
}
#heading {
text-align: center;
/* vertical-align: middle; */
}
Comments
Post a Comment