Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guess input #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/components/Form/Form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';

function Form() {
const [input, setInput] = React.useState('');
function guessing(event){
event.preventDefault();
console.log({input});
setInput('');
}
return(
<form className='guess-input-wrapper' onSubmit={guessing}>
<label htmlFor='guess-input'>Enter Guess:</label>
<input
required
minLength={5}
maxLength={5}
pattern="[a-zA-Z]{5}"
title="5 letter word"
id='guess-input'
type='text'
value={input}
onChange={(event) => (
setInput(event.target.value.toUpperCase())
)}
/>
</form>
);
}

export default Form;
2 changes: 2 additions & 0 deletions src/components/Form/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Form';
export { default } from './Form';
7 changes: 6 additions & 1 deletion src/components/Game/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import React from 'react';

import { sample } from '../../utils';
import { WORDS } from '../../data';
import Form from '../Form/Form';

// Pick a random word on every pageload.
const answer = sample(WORDS);
// To make debugging easier, we'll log the solution in the console.
console.info({ answer });

function Game() {
return <>Put a game here!</>;
return(
<>
<Form />
</>
);
}

export default Game;