Skip to content
조회 수 53919 추천 수 0 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

지정한 이미지파일명을 출력 시키는 시험문제풀이

아래의 조건대로 html나 자바스크립트 등으로 코딩을 만들 수 있겠어?

 

 

   시험문제 : *.png

 

   시험문제파일은 

      예를들어 1-2.png 가 있다고 가정하면 

      앞자리 1은 시험문제번호이며, "-"뒤의 숫자2는 문제의 정답이다.

      현재폴더안에 png 파일을 모두 불러와서 한개씩 랜덤으로 시험문제를 출력한다.

      1회차에 전체문제가 고르게 한번씩만 랜덤으로 나오게 하고, 모든문제가 한번씩 다 나왔으면 

      2회차에서도 전체문제가 고르게 한번씩만 랜덤으로 나오게 하면서 5회차까지 다 나오면 

      문제풀이는 회차별 점수를 출력하고, 확인을 누르면 종료한다. 

      단, 해당 회차에는 같은문제가 1회만 출제되어야 해.

      다음문제로 넘어갈때 정답 입력하는 곳에 숫자가 초기화가 안되고 그대로 남아 있으면 안돼. 초기화를 부탁해.

 

  화면의 레이아웃은

   

   회차 = 이미지를 처음 불러올 경우 1회차,

          모든이미지를 한번씩 다 불러온 뒤부터는 2회차이며 이후 계속 회차가 증가한다.

 

   총문제수 = png 이미지파일의 개수

   출제된 문제수 = 회차에 출제된 문제수

   남은 문제수 = 회차에 아직 출제되지 않은 문제수

   맞춘 문제수 = 출제된 문제수 중 정답을 맞춘 문제수

   맞춘 문제수 = 출제된 문제수 중 정답을 틀린 문제수

 

   맨밑의 가운데에 이미지 파일명을 적어줘.

   상단 가운데에 [회차] / [총문제수] / [출제된 문제수] / [남은 문제수] / [맞춘 문제수] / [틀린 문제수] 를 표시한다.

   화면가운데에 문제 이미지를 출력하고,

   이미지 밑에 정답을 입력할수 있고, 

   옆에 [정답확인] 이라는 버튼을 누르거나 엔터키를 입력하면 정답을 확인할 수 있다.

   정답을 맞추면 ok.mp3를 들려주고,

   정답을 틀리면 nono.mp3를 들려준다.

   정답이 틀린 경우 정답은 [ ]번 입니다. 라는 팝업창이 떳다가 2초뒤에 사라지게 한다.

   팝업 배경색상은 #cc6699, 글자색상은 #fffff 글자는 두껍게 한다.

 

 


 

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Study</title>

    <style>

        body {

            text-align: center;

            margin-top: 50px;

        }

        

        #header {

            margin-bottom: 20px;

        }

 

        #question-container {

            margin-top: 50px;

        }

 

        #image-name {

            margin-top: 20px;

        }

 

        /* Added styles for the popup */

        .popup {

            position: fixed;

            top: 50%;

            left: 50%;

            transform: translate(-50%, -50%);

            background: #cc6699; /* Background color */

            padding: 10px;

            border: 1px solid #000;

            color: #ffffff; /* Text color */

            font-weight: bold; /* Font weight */

        }

    </style>

</head>

<body>

    <div id="header">

        <p id="status"></p>

    </div>

    

    <div id="question-container">

        <img id="question-image" alt="Question Image">

        <br>

        <input type="text" id="answer-input" placeholder="정답을 입력하세요" onkeydown="if (event.key === 'Enter') checkAnswer()">

        <button onclick="checkAnswer()">정답확인</button>

    </div>

    

    <div id="image-name"></div>

 

    <script>

        let rounds = 1;

        let totalQuestions = 0;

        let answeredQuestions = 0;

        let correctAnswers = 0;

        let incorrectAnswers = 0;

        let remainingQuestions = [];

 

        function loadQuestions() {

            const imgExtensions = ['png', 'jpg', 'jpeg', 'gif'];

 

            // Load all image files in the current folder

            const imagesFolder = '';

            const imgFiles = ['1-3.png', '2-1.png', '3-3.png', '4-4.png', '5-5.png', '6-2.png', '7-3.png'];

 

            // Shuffle the array to get a random order for each round

            imgFiles.sort(() => Math.random() - 0.5);

 

            for (let i = 0; i < imgFiles.length; i++) {

                remainingQuestions.push(imgFiles[i]);

            }

 

            totalQuestions = remainingQuestions.length;

        }

 

        function getNextQuestion() {

            if (remainingQuestions.length === 0) {

                endQuiz();

                return;

            }

 

            const currentQuestion = remainingQuestions.pop();

            document.getElementById('question-image').src = currentQuestion;

            document.getElementById('image-name').innerText = `이미지 파일명: ${currentQuestion}`;

            document.getElementById('answer-input').value = ''; // Clear the answer input

            answeredQuestions++;

            updateStatus();

        }

 

        function checkAnswer() {

            const userAnswer = document.getElementById('answer-input').value;

            const correctAnswer = document.getElementById('question-image').src.split('-')[1].split('.')[0];

 

            if (userAnswer === correctAnswer) {

                playAudio('ok.mp3');

                correctAnswers++;

            } else {

                playAudio('nono.mp3');

                incorrectAnswers++;

                showCorrectAnswer(correctAnswer);

            }

 

            updateStatus();

            getNextQuestion();

        }

 

        function playAudio(audioFile) {

            const audio = new Audio(audioFile);

            audio.play();

        }

 

        function updateStatus() {

            document.getElementById('status').innerText = `회차: ${rounds} / 총문제수: ${totalQuestions} / 출제된 문제수: ${answeredQuestions} / 남은 문제수: ${totalQuestions - answeredQuestions} / 맞춘 문제수: ${correctAnswers} / 틀린 문제수: ${incorrectAnswers}`;

        }

 

        function endQuiz() {

            alert(`회차별 점수\n맞춘 문제수: ${correctAnswers}\n틀린 문제수: ${incorrectAnswers}`);

            rounds++;

            answeredQuestions = 0;

            correctAnswers = 0;

            incorrectAnswers = 0;

 

            // Reset questions for the next round

            remainingQuestions = [];

            loadQuestions();

            getNextQuestion();

        }

 

        function showCorrectAnswer(correctAnswer) {

            const popup = document.createElement('div');

            popup.className = 'popup'; // Add the popup class

            popup.innerText = `정답은 [${correctAnswer}]번 입니다.`;

            document.body.appendChild(popup);

 

            setTimeout(() => {

                document.body.removeChild(popup);

            }, 1000);

        }

 

        // Initialize the quiz

        loadQuestions();

        updateStatus();

        getNextQuestion();

    </script>

</body>

</html>

 

 

 

 

로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
897 컴퓨터잡담 H734GP 공유기 시스템로그 중 >>> Send Offer / Receive Discover / 2023.06.04 51486
896 WindowsTip VBS) FTP.scriptlet and Shell.scriptlet 2013.09.21 48506
895 파이썬 python AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector' 해결방법 2023.05.07 47493
894 AutoHotKey AHK) 보안프로그램 등으로 화면복사(Printscreen) 안될때 사용방법 1 12 file 2012.11.21 47165
893 프로세스 pinomate.exe 프로세스 삭제방법 6 2011.02.13 45998
892 WindowsTip VBS) PostMessage or SendMessage to external program 2013.09.21 45965
891 컴퓨터잡담 [PHP] 원격지의 이미지 사이즈 구하는 방법 2 2009.08.11 44528
890 AutoHotKey Ahk) 웹페이지 감시결과에 따라 마이피플로 글 전송하기 12 file 2013.01.06 44023
889 컴퓨터잡담 emule 서버리스트 2010.11.10 43048
888 Excel Excel Vba) 셀의 행, 열(column, row) 주소 알아내기 또는 삽입하기 더불어 제어하기 2012.01.05 42974
887 컴퓨터잡담 2023-09-23 서버다운 후 복구완료 secret 2023.09.23 42526
886 AutoHotKey Autohotkey) 화면보호기(ScreenSaver) On/Off 방법 17 2012.03.16 40675
885 [Docs]스프레드시트 구글 스프레드시트에서 셀값이 특정일에서 현재일과 3일 이내의 범위에 들어오면 이메일을 발송하는 방법 2023.03.26 40472
884 Excel GET.CELL 매크로함수 응용 11 2012.07.16 40175
883 컴퓨터잡담 안드로이드 동영상 재생시 파란색 물음표 박스만 나올때 조치방법 2 file 2013.04.26 39285
882 컴퓨터잡담 URL Encoding 특수문자코드 4 2012.03.30 39063
881 컴퓨터잡담 mysql 날짜타입에 기본값으로 현재시간넣기 1 2009.12.07 38588
880 AutoHotKey ahk) 오토핫키 콤보박스 제어하기 file 2013.10.30 38176
879 WindowsTip 네트워크에 있는 다른 시스템과 ip 주소가 충돌합니다. 1 file 2013.03.29 38112
878 컴퓨터잡담 테블릿을 세컨트모니터로??? 2023.04.26 38043
Board Pagination Prev 1 2 3 4 5 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소