اختبار
اختبار الأسئلة
النتيجة النهائية
body {
font-family: Arial, sans-serif;
direction: rtl;
text-align: center;
}
#quiz-container {
max-width: 500px;
margin: 50px auto;
}
button {
margin-top: 20px;
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
input {
padding: 10px;
margin: 20px 0;
font-size: 16px;
}
const questions = [
{ question: "ما هو عاصمة فرنسا؟", options: ["باريس", "لندن", "روما"], correct: 0 },
{ question: "ما هو عدد كواكب المجموعة الشمسية؟", options: ["8", "9", "10"], correct: 0 },
{ question: "ما هو أكبر محيط في العالم؟", options: ["المحيط الأطلسي", "المحيط الهندي", "المحيط الهادي"], correct: 2 },
{ question: "ما هي أسرع طائرة في العالم؟", options: ["SR-71", "F-16", "بوينغ 747"], correct: 0 },
{ question: "كم عدد أيام الأسبوع؟", options: ["6", "7", "8"], correct: 1 },
{ question: "ما هو أعلى جبل في العالم؟", options: ["إفرست", "كليمنجارو", "الهيمالايا"], correct: 0 },
{ question: "كم عدد الأضلاع في المربع؟", options: ["3", "4", "5"], correct: 1 },
{ question: "ما هو أكبر دولة في العالم من حيث المساحة؟", options: ["الصين", "الولايات المتحدة", "روسيا"], correct: 2 },
{ question: "كم عدد حروف الأبجدية العربية؟", options: ["26", "28", "30"], correct: 1 },
{ question: "من هو مؤلف رواية 'الحرب والسلام'؟", options: ["تولستوي", "دوستويفسكي", "هيمنغواي"], correct: 0 },
];
let selectedQuestions = [];
let currentQuestionIndex = 0;
let score = 0;
let username = '';
function startQuiz() {
username = document.getElementById('username').value;
if (username.trim() === '') {
alert("يرجى إدخال اسمك.");
return;
}
selectedQuestions = getRandomQuestions(10);
document.getElementById('welcome-screen').style.display = 'none';
document.getElementById('question-screen').style.display = 'block';
showQuestion();
}
function getRandomQuestions(num) {
let shuffled = [...questions].sort(() => Math.random() - 0.5);
return shuffled.slice(0, num);
}
function showQuestion() {
const questionData = selectedQuestions[currentQuestionIndex];
document.getElementById('question').innerText = questionData.question;
const optionsContainer = document.getElementById('options');
optionsContainer.innerHTML = '';
questionData.options.forEach((option, index) => {
const optionElement = document.createElement('button');
optionElement.innerText = option;
optionElement.onclick = () => checkAnswer(index);
optionsContainer.appendChild(optionElement);
});
}
function checkAnswer(selectedOptionIndex) {
const correctOptionIndex = selectedQuestions[currentQuestionIndex].correct;
if (selectedOptionIndex === correctOptionIndex) {
score++;
}
nextQuestion();
}
function nextQuestion() {
currentQuestionIndex++;
if (currentQuestionIndex < selectedQuestions.length) {
showQuestion();
} else {
showResult();
}
}
function showResult() {
document.getElementById('question-screen').style.display = 'none';
document.getElementById('result-screen').style.display = 'block';
const scorePercentage = (score / selectedQuestions.length) * 100;
document.getElementById('score').innerText = `نتيجتك: ${score}/${selectedQuestions.length}`;
let message;
if (scorePercentage >= 80) {
message = `أحسنت يا ${username}! لقد حققت نتيجة رائعة!`;
} else if (scorePercentage >= 50) {
message = `عمل جيد يا ${username}. يمكنك تحسين نتيجتك أكثر.`;
} else {
message = `لا تقلق يا ${username}. حاول مرة أخرى وستكون أفضل في المرة القادمة!`;
}
document.getElementById('message').innerText = message;
}
Commentaires
Enregistrer un commentaire