@extends('frontend.layouts.app') @php $status = \Illuminate\Support\Facades\Cookie::get('Rstatus'); $cookie = \Illuminate\Support\Facades\Cookie::get('userSelectedanswers'); $userSelectedAnswers = json_decode($cookie, true); $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) }}%