Assesment

 

import React, { Component } from 'react';
import './form.css';

class Exam extends Component {
  constructor(props) {
    super(props);
    this.state = {
      questions: [
        {
          id: 1,
          question: 'What is the pH value of the human body?',
          options: ['9.2-9.8', '7.0-7.8', '6.1-6.3', '5.4-5.6'],
          correctAnswer: '7.0-7.8',
          selectedAnswer: null,
        },
        {
          id: 2,
          question: 'Which of the following are called "Key Industrial animals"?',
          options: ['Producers', 'Tertiary consumers', 'Primary consumers', 'None of these'],
          correctAnswer: 'Primary consumers',
          selectedAnswer: null,
        },
        {
          id: 3,
          question: 'What is the Full Form of MSU?',
          options: ['Maharaja', 'Sayajirao', 'University', 'Maharaja Sayajirao University of Baroda'],
          correctAnswer: 'Maharaja Sayajirao University of Baroda',
          selectedAnswer: null,
        },
        {
          id: 4,
          question: 'What is the Full Form of WAD?',
          options: ['web', 'application', 'developer', 'Web Application Development'],
          correctAnswer: 'Web Application Development',
          selectedAnswer: null,
        },
        {
          id: 5,
          question: 'What is the Full Form of MAD?',
          options: ['mobile', 'application', 'development', 'Mobile Application Development'],
          correctAnswer: 'Mobile Application Development',
          selectedAnswer: null,
        },
        {
          id: 6,
          question: 'What is the Full Form of ST?',
          options: ['software', 'tester', 'QA', 'Software Testing'],
          correctAnswer: 'Software Testing',
          selectedAnswer: null,
        },
        {
          id: 7,
          question: 'What is the Full Form of SE?',
          options: ['software', 'engineer', 'QA', 'Software Engineering'],
          correctAnswer: 'Software Engineering',
          selectedAnswer: null,
        },
        {
          id: 8,
          question: 'What is the Full Form of CS?',
          options: ['computer', 'science', 'Computer Science', 'None'],
          correctAnswer: 'Computer Science',
          selectedAnswer: null,
        },
        {
          id: 9,
          question: 'What is the Full Form of BCA?',
          options: ['batch', 'applications', 'Bachelor of Computer Applications', 'None of these'],
          correctAnswer: 'Bachelor of Computer Applications',
          selectedAnswer: null,
        },
        {
          id: 10,
          question: 'What is the Full Form of DCA?',
          options: ['department', 'applications', 'Department of Computer Applications', 'None of these'],
          correctAnswer: 'Department of Computer Applications',
          selectedAnswer: null,
        },
       
             ],
      currentQuestion: 0,
      trueCount: 0,
    };
  }

  handleOptionSelect = (selectedAnswer) => {
    const { questions, currentQuestion, trueCount } = this.state;
    const currentQuestionData = questions[currentQuestion];

    if (selectedAnswer === currentQuestionData.correctAnswer) {
      this.setState({ trueCount: trueCount + 1 });
    } else {
      this.setState({ trueCount: trueCount - 1 });
    }

    currentQuestionData.selectedAnswer = selectedAnswer;

   
    if (currentQuestion < questions.length - 1) {
      this.setState({ currentQuestion: currentQuestion + 1 });
    }
  };

  render() {
    const { questions, currentQuestion, trueCount } = this.state;
    const currentQuestionData = questions[currentQuestion];

    return (
      <div className='form-container'>
        <h1 className="form-header">WAD Assessment</h1>
        {questions.map((question) => (
          <div key={question.id} className="question">
            <p>{question.question}</p>
            <ul>
              {question.options.map((option) => (
                <li key={option}>
                  <label>
                    <input
                      type="radio"
                      name={`question_${question.id}`}
                      value={option}
                      checked={option === question.selectedAnswer}
                      onChange={() => this.handleOptionSelect(option)}
                    />
                    {option}
                  </label>
                </li>
              ))}
            </ul>
          </div>
        ))}
        <div className="error-message">
          <p>True Count: {trueCount}</p>
        </div>
      </div>
    );
  }
}

export default Exam;







/* FormExample.css */
.form-container {
    width: fit-content;
    height: auto;
    text-align: left;
    background-color: #f0f0f0;
    padding: 20px;
  }
 
  .form-header {
    background-color: #333;
    color: #fff;
    padding: 10px;
    text-align: center;}
 
 
 
  .question {
    margin-left: 10px;
    margin-top: 5px;
    background-color: #f7f7f7;
    border: 1px solid #ccc;
    padding: 10px;
    box-shadow: 3px 3px 5px #888888;
    border-radius: 8px; }
 
 
 
  .error-message {
    margin-left: 170px;
    color: rgb(0, 0, 0);
    font-size: large;
    font-weight: bold;
  }


Comments