@extends('frontend.layouts.app') @php $cookie = \Illuminate\Support\Facades\Cookie::get('EuserSelectedanswers'); $userSelectedAnswers = json_decode($cookie, true); $username = Auth::user()->name; $totalQuestions = count($questions); $correctCount = 0; $incorrectCount = 0; foreach ($questions as $question) { $selectedAnswer = $userSelectedAnswers[$question->id] ?? null; $correctAnswer = $question->answer->where('is_correct', '1')->first(); if ($selectedAnswer && $correctAnswer && $selectedAnswer == $correctAnswer->id) { $correctCount++; } elseif ($selectedAnswer) { $incorrectCount++; } } @endphp @push('css') @endpush @section('content')
Final Score
{{ number_format(($correctCount / $totalQuestions) * 100, 2) }}%
FILTER QUESTIONS
Date Completed: {{date('d-m-y')}}