Skip to content
조회 수 53922 추천 수 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
번호 분류 제목 날짜 조회 수
61 사건사고 진실이 궁금하다. 2021.09.17 2212
60 사건사고 문재인 고위고직자 임명기준 2018.10.03 5379
59 사건사고 하동지역 무허가 축사 적법화 강력 추진 2018.06.28 5817
58 사건사고 다스는 누구겁니까 2017.10.27 5599
57 사건사고 프렌치불독 자나깨나 개조심 file 2017.10.24 6060
56 사건사고 김대중 북한 핵개발 발언 secret 2017.10.13 450
55 사건사고 박근혜 대통령 탄핵심판 파면 결정 file 2017.03.10 4991
54 사건사고 박근혜 대통령 생각 file 2016.12.15 4429
53 사건사고 탄핵 소추안 가결 직후 정치변화 file 2016.12.09 4099
52 사건사고 김윤석 무릎담요 성희롱 논란 김윤석이 이상한건가? file 2016.12.05 7894
51 사건사고 정유섭 세월호 7시간 대통령은 노셔도 되는 사람 file 2016.12.05 4145
50 사건사고 정윤회 아들 정우식 옥중화 출연소감 file 2016.12.02 12999
49 사건사고 표창원 탄핵추진 반대 의원 명단 공개 file 2016.11.30 5191
48 사건사고 문재인 손석희 예리한 질문에 무너졌다 file 2016.11.28 21211
47 사건사고 소율 문희준 결혼 쇼킹하다 file 2016.11.24 5539
46 사건사고 청와대 비아그라 고산병 효능 검증실험 중 2 file 2016.11.23 6624
45 사건사고 박근혜 길라임 내가 이럴려고 차움병원 다녔나? file 2016.11.16 4361
44 사건사고 박근혜 대통령 트럼프 통화의 진실 file 2016.11.11 4727
43 사건사고 최순실 정맥주사 청와대로 외부반출 핫이슈 file 2016.11.10 4588
42 사건사고 김병준 교수 새 국무총리 누구시더라? file 2016.11.02 7489
Board Pagination Prev 1 2 3 4 Next
/ 4

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소