-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (34 loc) · 974 Bytes
/
index.js
File metadata and controls
39 lines (34 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const letters = ["B", "e", "a", "r"];
let word = letters.join("");
function stringToArray(str) {
return str.split("")
}
function variar(str){
let arr = stringToArray(str)
for (let i = arr.length -1; i>0; i--){
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]]
}
return arr.join("")
}
class Bear extends React.Component {
constructor(props) {
super(props);
this.state = { word: variar(word) };
this.randomizeWord = this.randomizeWord.bind(this);
}
randomizeWord() {
this.setState({ word: variar(word) });
}
render() {
return (
<div id="corpo" className="center">
<div>
<h1>{this.state.word}</h1>
<button onClick={this.randomizeWord}>Randomizar</button>
</div>
</div>
);
}
}
ReactDOM.render(<Bear />, document.querySelector("#app"));