Inflearn brand logo image

인프런 커뮤니티 질문&답변

안연수님의 프로필 이미지
안연수

작성한 질문수

웹 프론트엔드를 위한 자바스크립트 첫걸음

API를 사용해 명언 설정하기

명언 설정하는데 위치설정 오류가 있어요!

해결된 질문

작성

·

76

·

수정됨

0

질문 작성법

  • 세션 7 - 4.API를 사용해 명언

화면 캡처 2025-05-21 140603.png.webp

강사님처럼 명언을 검색바 밑으로 보여지게 출력하고 싶은데요, 저는 오른쪽으로 명언이 출력되요! 명언바 위치 설정을 어떻게 해야 하는 지 궁금해요?!

const API_URL = "https://random-quote.hyobb.com/";
const quoteElement = document.getElementById("quote");
const quoteItem = localStorage.getItem("quote");

const nowDate = new Date();
const month = nowDate.getMonth() + 1;
const date = nowDate.getDate();

const setQuote = (result) => {
  let quote = { createDate: `${month}-${date}`, quoteDate: result };
  localStorage.setItem("quote", JSON.stringify(quote));
  quoteElement.textContent = result;
};

const getQuote = async () => {
  try {
    const data = await fetch(API_URL).then((res) => res.json());
    const result = data[1].respond;
    setQuote(result);
  } catch (err) {
    console.log(`err:${err}`);
    setQuote("작은 기회로 부터 종종 위대한 업적이 시작된다. - 데모스테네스");
  }
};

getQuote();

답변 2

1

효빈 Hyobin님의 프로필 이미지
효빈 Hyobin
지식공유자

우선 html 파일의 코드 확인이 필요할 것 같습니다.
명언이 들어갈 div의 위치를 아래와 동일하게 배치했는지 확인해보시고, 그럼에도 오른쪽에 배치되신다면, 다시 한 번 질문 남겨주세요!

    <div class="main-container">
        <div class="main-wrapper">
            <div class="today-info">
                <div class="date" id="date">
                    <!-- 날짜&요일 -->
                </div>
                <div class="time" id="time">
                    <!-- 현재 시간 -->
                </div>
            </div>
            <div class="search">
                <input id="search-input" autocomplete="off" placeholder="검색어를 입력하세요" />
            </div>
        </div>
        <div class="quote" id="quote">
							<!-- 명언 -->
				</div>
    </div>

0

안연수님의 프로필 이미지
안연수
질문자

끝까지 강의 대로 코드를 완성해나가니, 강사님처럼 똑같은 결과물이 나왔어요, 답변 감사드립니다ㅠㅠ

안연수님의 프로필 이미지
안연수

작성한 질문수

질문하기