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
22 changes: 22 additions & 0 deletions Country/Country.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="CountryStyleSheet.css">
<title>나라 검색기</title>
</head>
<body>
<div id="mainBox">
<h1>나라 검색기</h1>
<div id="searchBox">
<input type="text" id="countryInput" placeholder="나라 이름을 입력하세요">
<button id="searchButton">검색</button>
</div>
<div id="result"></div>
</div>
<script src="CountryJS.js"></script>
</body>
</html>


40 changes: 40 additions & 0 deletions Country/CountryJS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
document.getElementById("searchButton").addEventListener("click", async function() {
const countryName = document.getElementById("countryInput").value
if (!countryName) {
alert("나라 이름을 입력하세요!");
return;
}
Comment on lines +1 to +6

Choose a reason for hiding this comment

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

함수 안에 내용이 많아서 이 함수가 어떤 기능을 하는 함수인지 잘 모르겠어요..! 따라서 익명 함수보다는 함수 이름을 지정해서 어떤 함수인지 함수명을 통해 알 수 있게 하면 좋을 것 같아요! 🙂

Copy link
Author

Choose a reason for hiding this comment

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

넵 익명 함수를 활용하기 보다는 함수 이름을 지정해서 가독성을 키울 수 있는 코드를 짜도록 하겠습니다. 감사합니다!


const response = await fetch(`https://restcountries.com/v3.1/name/${countryName}`);

if (response.status === 404) {
document.getElementById("result").innerText = "해당 나라를 찾을 수 없습니다.";
return;
}
Comment on lines +10 to +13

Choose a reason for hiding this comment

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

const result = document.getElementById("result");

result.innerText = " ";

와 같이 가독성있게 작성하는 것도 좋을 것 같아요! 아래에도 result 객체가 또 쓰일 수도 있고 하니까 !

Copy link
Author

Choose a reason for hiding this comment

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

if문 밖에 const result = document.getElementById("result");를 정의하였더니 재사용이 가능해져서 코드도 줄어들고 가독성이 좋아졌습니다. 조언 감사합니다!


const data = await response.json();

const country = data.find(c => c.name.common.toLowerCase() === countryName.toLowerCase());

if (!country) {
document.getElementById("result").innerText = "나라 이름을 정확히 입력해주세요.";
return;
}

const flagUrl = country.flags.png;
let capital;
if(country.capital) {
capital = country.capital[0];
}
else {
capital = "정보 없음";
}

document.getElementById("result").innerHTML = `
<h2>${country.name.common}</h2>
<p><strong>수도:</strong> ${capital}</p>
<img src="${flagUrl}" alt="국기" width="200">
`;
});


23 changes: 23 additions & 0 deletions Country/CountryStyleSheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
body {
display: flex;
align-items: center;
justify-content: center;
background-color: gainsboro;
}

#mainBox {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 300px;
background-color: white;
border-radius: 5px;
}
Comment on lines +15 to +16

Choose a reason for hiding this comment

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

border-radius를 지정한 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

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

모서리를 둥글게 만드는 게 더 가시성있다고 생각하여 지정하였습니다. 디자인적 요소가 아닌 다른 의도한 바는 없습니다!


#result {
margin-top: 20px;
margin-bottom: 20px;
}
Comment on lines +18 to +21

Choose a reason for hiding this comment

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

만약 위 아래만 margin을 주고 싶다면, margin-topmargin-bottom을 따로 지정하지 않고
margin: 20px 0; 으로 하면 왼쪽은 상하, 오른쪽은 좌우 px을 지정할 수 있습니다!

Copy link
Author

Choose a reason for hiding this comment

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

더 효율적인 코드 알려주셔서 감사합니다. 수정하겠습니다!



2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# FrontEnd_2025-1
2025년 상반기 프론트엔드 비기너 학습 레포
2025년 상반기 프론트엔드 비기너 학습 레포
109 changes: 109 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const $makeNumButton = document.querySelector("#makeNumButton");
const $resultNums = [];
for(let i = 1; i<=6; i++){
const el = document.querySelector(`#resultNum${i}`);
$resultNums.push(el);
}
const $buyLottoButton = document.querySelector("#buyLottoButton");
const $myNums = [];
for(let i = 1; i<=6; i++){
const el = document.querySelector(`#myNum${i}`);
$myNums.push(el);
}
const $lottoResultText = document.querySelector(".lottoResultText");
const $input = document.querySelector("input");
const $price = document.querySelector("#price");
const $resultBox = document.querySelector(".resultBox");
const $myNumBox = document.querySelector(".myNumBox");
const $container = document.querySelector(".container");

let resultLottoNumber = []; //로또 결과 배열 선언
let myLottoNumber = []; //내 결과 배열 선언
let newNumbers = []; //복제 배열 선언

function randomNum() {
let number = new Set(); //중복 방지를 위한 set
while (number.size < 6) {
number.add(Math.floor(Math.random() * 45) + 1); //1~45 사이의 난수 생성
}
const randomNumarr = [...number].sort((a, b) => a - b) //Set을 배열로 바꾼 후 오름차순 정렬
return randomNumarr;
}

function crossCheck(arr1, arr2) { //배열끼리 몇 개 일치하는지 비교하는 함수
let match = 0;
for(let i=0; i<6; i++) {
if (arr2.includes(arr1[i])) {
match++;
}
}
return match;
}

$makeNumButton.addEventListener('click', function() { //번호 생성 클릭 이벤트

resultLottoNumber = randomNum();
for(let i=0; i<6; i++) { //로또 결과 배열에 랜덤 수 삽입
$resultNums[i].innerText = resultLottoNumber[i];
}

});

let buyButtonCount = 0;
$buyLottoButton.addEventListener('click', function() { //구매하기 클릭 이벤트

const matchCount = crossCheck(resultLottoNumber, myLottoNumber); //로또 결과 배열, 내 결과 배열 비교

if(resultLottoNumber.length === 0) { //로또 결과 배열이 없을 시 경고 및 새로고침
alert("먼저 로또 번호를 생성해주세요!");
location.reload();
}
else { //로또 결과 텍스트 삽입
$lottoResultText.innerText = `결과: ${matchCount}개 일치`
}

const inputvalue = parseInt($input.value); //입력값
$price.innerText = `${inputvalue*1000}`; //금액 텍스트 삽입

if(isNaN(inputvalue) || inputvalue <= 0) { //입력값 1이상 아니면 경고 및 새로고침
alert("구매 수량을 제대로 입력하세요!");
$input.focus();
}
else {
buyButtonCount++; // 구매하기 버튼 두 번 누르면 버튼 비활성화
if(buyButtonCount > 1) {
$buyLottoButton.disabled(true);
}

myLottoNumber = randomNum();
for(let i=0; i<6; i++) { //내 결과 배열에 랜덤 수 삽입
$myNums[i].innerText = myLottoNumber[i];
}

const cloneCount = inputvalue - 1; // 몇 번 복제할지 결정
let height = 0; //높이

for (let i = 0; i < cloneCount; i++) {
//내 결과 복제
const clonedMyNumBox = $myNumBox.cloneNode(true);
const clonedCircles = clonedMyNumBox.querySelectorAll(".circle");

newNumbers = randomNum();
clonedCircles.forEach((circle, index) => { //복제 구에 숫자 채워 넣기
circle.innerText = newNumbers[index];
});

const clonedResultText = clonedMyNumBox.querySelector(".lottoResultText"); //로또 결과 배열, 내 결과 복제 비교
const matchCount = crossCheck(resultLottoNumber, newNumbers);
clonedResultText.innerText = `결과: ${matchCount}개 일치`

$resultBox.appendChild(clonedMyNumBox); // resultBox에 추가

if (inputvalue > 2) height += 125; //높이 누적
}

if(inputvalue > 2) height -= 125; // 높이 조정 (inputvalue가 2면 height는 0이므로 원래 높이 그대로 유지)
$container.style.height = `${1000 + height}px`;
$resultBox.style.height = `${460 + height}px`;
}
});
72 changes: 72 additions & 0 deletions startlotto.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>로또 번호 생성기</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:[email protected]&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<header>
<span class="headingText">로또 번호 생성기</span>
<span class="headingTextSub">행운의 번호를 생성해보세요!</span>
</header>
<div class="bodyBox">
<div class="makeNumBox">
<span class="makeNumText">번호 생성</span>
<div class="circleBox">
<span class="circle" id="circle1">?</span>
<span class="circle" id="circle2">?</span>
<span class="circle" id="circle3">?</span>
<span class="circle" id="circle4">?</span>
<span class="circle" id="circle5">?</span>
<span class="circle" id="circle6">?</span>
</div>
<button id="makeNumButton">번호 생성하기</button>
</div>
<div class="buyLottoBox">
<span class="buyLottoText">로또 구매하기</span>
<div class="inputBox">
<span class="buyAmountText">구매 수량:</span>
<input>
</div>
<span class="totalText">총 금액: <span id="price">0</span>원 (1장당 1,000원)</span>
<button id="buyLottoButton">구매하기</button>
</div>
<div class="resultBox">
<div class="resultCheckBox">
<span class="resultCheckBoxText">당첨 결과 확인</span>
<span class="thisWeekResultText">이번 주 당첨 번호:</span>
<div class="circleBox">
<span class="circle" id="resultNum1">?</span>
<span class="circle" id="resultNum2">?</span>
<span class="circle" id="resultNum3">?</span>
<span class="circle" id="resultNum4">?</span>
<span class="circle" id="resultNum5">?</span>
<span class="circle" id="resultNum6">?</span>
</div>
<span class="myNumText">내가 구매한 번호:</span>
</div>
<div class="myNumBox">
<div class="circleBox">
<span class="circle" id="myNum1">?</span>
<span class="circle" id="myNum2">?</span>
<span class="circle" id="myNum3">?</span>
<span class="circle" id="myNum4">?</span>
<span class="circle" id="myNum5">?</span>
<span class="circle" id="myNum6">?</span>
</div>
<div class="lottoResultBox">
<span class="lottoResultText">결과:</span>
</div>
</div>
</div>
</div>
</div>
<script src="script.js" defer></script>
</body>
</html>
Loading