Skip to content
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
9 changes: 9 additions & 0 deletions button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function ColorBtn ({ $target, onClick }) {
const colorBtn = document.createElement('button')
colorBtn.innerText = 'Pick Colors!'
$target.appendChild(colorBtn)

colorBtn.addEventListener('click', () => {
onClick()
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • github에 올린 파일 끝에 ⛔ 요런 모양의 아이콘이 뜨는 이유는 마지막 줄을 개행을 하지 않아서 그런 건데요. 파일 끝에는 항상 개행을 해야한다고 해요. EOL(End of Line) 혹은 EOF(End of File)라고 하더라고요. 자세한 내용은 이 링크를 참고해보셔요.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오오 항상 그 의미가 뭐지?!! 하고 궁금했었는데 경희님 덕에 알아갑니다! 감사해요❤

13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Colors</title>
<meta charset="utf-8">
<link rel="shortcut icon" href="picker.png">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파비콘 추가까지...! 규란님의 세심함에 감탄하고 갑니다 👍

<link rel="stylesheet" href="main.css">
</head>
<body>
<main></main>
<script src="main.js" type="module"></script>
</body>
</html>
45 changes: 45 additions & 0 deletions m2-gradient/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import ClickBtn from "./button.js"
import Detail from "./detail.js"

export default function App ({ target }) {

const picker = () => {
const hexString = '0123456789abcdef'
const pickIndex = () => Math.floor(Math.random() * 16)
const hexColorCode = () => {
let temp = '#'
for (let i = 0; i < 6; i++){
const index = pickIndex()
temp += hexString[index]
}
return temp;
}
return hexColorCode();
}
Comment on lines +6 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 랜덤 색상 코드 생성하는 함수 보고 이렇게도 할 수 있구나 하고 인사이트를 얻어 갑니다! 저는 16777215까지 난수를 만들고 16진수로 바꿔주는 방식을 사용해서 6자리보다 작은 자리수의 난수가 반환되는 경우도 생기더라고요. 규란님 방식은 꼭 6자리가 나오니까 더 깔끔하게 코드 구현이 가능한 것 같네요!


const way = () => {
const ways = ['right', 'left']
const pickIndex = () => Math.floor(Math.random() * 2)
return ways[pickIndex()]
}

const detail = new Detail({
target,
initialState: {
way: 'right',
start: '#ffffff',
end: '#ffffff'
}
})

new ClickBtn({
target,
onClick: () => {
detail.setState({
way: way(),
start: picker(),
end: picker()
})
}
})
}
9 changes: 9 additions & 0 deletions m2-gradient/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function ClickBtn ({ target, onClick }) {
const clickBtn = document.createElement('button')
clickBtn.innerText = 'Click Me'
target.appendChild(clickBtn)

clickBtn.addEventListener('click', () => {
onClick()
})
}
30 changes: 30 additions & 0 deletions m2-gradient/detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default function Detail ({ target, initialState }) {
const detail = document.createElement('div')
target.appendChild(detail)

this.state = initialState
this.setState = (nextState) => {
this.state = nextState
this.render()
}

this.render = () => {
const { way, start, end } = this.state
document.body.style.background = `
linear-gradient(to ${way}, ${start}, ${end})
`

detail.innerHTML = `
<p class="descript">
CLICK THE BUTTON BELLOW TO GENERATE
A RANDOM GRADIENT HEX COLOR COMBINATION
</p>

<p class="gradientColor">
background: linear-gradient(to ${way}, ${start}, ${end});
</p>
`
}

this.render()
}
13 changes: 13 additions & 0 deletions m2-gradient/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hex Colors</title>
<link rel="shortcut icon" href="picker.png">
<link rel="stylesheet" href="main.css">
</head>
<body>
<main></main>
<script src="main.js" type="module"></script>
</body>
</html>
48 changes: 48 additions & 0 deletions m2-gradient/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
main {
width: 98vw;
height: 98vh;
display: grid;
justify-content: center;
align-content: center;
}

div {
text-align: center;
}

.descript, .gradientColor {
width: 58vw;
font-size: 35px;
justify-self: center;
font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
-webkit-animation:colorchange 8s linear infinite alternate;
}

@-webkit-keyframes colorchange {
0% {
color: white;
}
30% {
color: gray;
}
60% {
color: darkgray;
}
100% {
color: black;
}
}

button {
transition : all 0.5s ease;
border: none;
font-size: 1rem;
padding: 0.7rem;
border-radius: 5px;
justify-self: center;
}

button:hover {
cursor:pointer;
background-color: rgb(197, 196, 196);
}
5 changes: 5 additions & 0 deletions m2-gradient/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import App from "./app.js"

const target = document.querySelector('main')

new App({ target })
Binary file added m2-gradient/picker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions m3-quote/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const API_URL = "https://free-quotes-api.herokuapp.com";

export const request = async () => {
try {
const res = await fetch(API_URL);
const result = await res.json();

if (!res.ok) {
throw new Error("api error!");
}
return result;
} catch (error) {
console.log(error.message);
}
};
12 changes: 12 additions & 0 deletions m3-quote/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import GenerateBtn from "./button.js";
import QuoteDetail from "./quotedetail.js";

export default function App({ target }) {
const quoteDetail = new QuoteDetail({ target });
new GenerateBtn({
target,
onClick: () => {
quoteDetail.render();
},
});
}
9 changes: 9 additions & 0 deletions m3-quote/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function GenerateBtn({ target, onClick }) {
const nextButton = document.createElement("button");
target.appendChild(nextButton);
nextButton.innerText = "▶";

nextButton.addEventListener("click", () => {
onClick();
});
}
15 changes: 15 additions & 0 deletions m3-quote/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Quote Generator</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<link rel="shortcut icon" href="quote.png">
<link rel="stylesheet" href="main.css">
</head>
<body>
<main>
</main>
<script src="main.js" type="module"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions m3-quote/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
body {
font-family: "Times New Roman", Times, serif;
height: 98vh;
background: #80e5ff;
display: grid;
justify-content: center;
align-content: center;
align-items: center;
}

main {
width: 50vw;
height: 40vh;
border-radius: 37px;
background: linear-gradient(to right, #55ddff, #72ffec);
box-shadow: -31px 31px 62px #6dc3d9, 31px -31px 62px #93ffff;
padding: 150px 70px 70px 70px;
display: grid;
grid-template-rows: repeat(3, 1fr);
justify-content: center;
align-content: center;
}

.quote,
.author {
width: 50vw;
text-align: center;
font-size: 3.4vh;
align-self: center;
}

.author {
font-size: 2.3vh;
font-style: italic;
}

button {
transition: all 0.2s ease-in-out;
background: transparent;
color: white;
border: none;
align-self: end;
justify-self: end;
text-align: center;
font-size: 3vh;
}

button:hover {
color: rgba(0, 47, 255, 0.644);
cursor: pointer;
}
5 changes: 5 additions & 0 deletions m3-quote/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import App from "./app.js";

const target = document.querySelector("main");

new App({ target });
Binary file added m3-quote/quote.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions m3-quote/quotedetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { request } from "./api.js";

export default function QuoteDetail({ target }) {
const quotearea = document.createElement("div");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명 quoteareaquoteArea와 같이 카멜 케이스로 작성해주면 더 좋을 것 같습니다! 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 세심하게 봐주시다니 감사합니다! 다음엔 멋진 변수 컨벤션으로 돌아오겠습니다. 꼼꼼한 피드백 감사해요!

const authorarea = document.createElement("div");
quotearea.className = "quote";
authorarea.className = "author";
target.appendChild(quotearea);
target.appendChild(authorarea);

this.render = async () => {
const randomQuote = await request();
const { quote, author } = randomQuote;
quotearea.innerText = `${quote.replace(/\uFFFD/g, "-")}`;
authorarea.innerText = `by. ${author.length > 0 ? author.replace(/\uFFFD/g, "-") : "Unknown"}`;
};

this.render();
}
30 changes: 30 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
body {
margin: 0;
padding: 0;
background-color: black;
}

main {
width: 98vw;
height: 98vh;
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

widthheight를 100이 아닌 98로 지정해주신 이유가 궁금합니다, 규란님!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 저도 이 부분이 궁금한데^_ㅠ 100으로 줘버리니까 갑자기 화면이 넘치는지 스크롤이 생겨버리더라고요 도대체 왜 그런 걸까요? 경희님 이유를 아시나요..? 이 지점에서 역시나 아직 CSS 부족한 부분이 많다는 걸 느끼게 되는 계기였습니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
body의 내장 스타일이 margin이 8px로 설정되어 있어서 스크롤이 생기는 것 같아요. 그런 기본적으로 내장되어 있는 스타일 때문에 레이아웃이 어그러지는 경우가 많아서 reset.css 같은 걸 이용해서 기본 스타일을 초기화해주곤 하는데요. 저는 요즘엔 귀찮아서 전체 선택자로 margin과 padding 정도만 0으로 초기화해서 씁니당..! 규란님 코드에선 우선 body만 margin: 0으로 초기화해주셔도 100vw, 100vh로 썼을 때 스크롤 안 생길 거예요!

display: grid;
justify-content: center;
align-content: center;
}

button {
transition : all 0.4s ease-out;
background: rgba(255, 255, 255, 0.342);
box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.37);
backdrop-filter: blur( 20px );
border-radius: 10px;
border: 1px solid rgba( 255, 255, 255, 0.18 );
font-size: 20px;
padding: 5px 10px 5px 10px;
color: white;
}

button:hover {
background: rgba(14, 14, 14, 0.85);
cursor: pointer;
}
30 changes: 30 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ColorBtn from "./button.js";

const body = document.querySelector('body')
const $target = document.querySelector('main')
let egg = 0;

const colorPicker = () => {
let targetColor = '#'
const hex = '0123456789abcdef'

const pickIndex = () => Math.floor( Math.random() * 16 );

for (let i = 0; i < 6; i++) {
const index = pickIndex();
targetColor += hex[index];
}

return targetColor;
}

new ColorBtn({
$target,
onClick: () => {
if (egg === 101) confirm("🎉 You've already clicked 100 times!\nDo you want to continue picking colors?")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗, 이스터 에그를 숨겨 놓으셨군요 ㅎㅎㅎ 센스 넘치시네요 👍

const color = colorPicker();
console.log(color);
body.style.backgroundColor = color;
egg++;
}
})
Binary file added picker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.