Skip to content

Latest commit

 

History

History
66 lines (56 loc) · 2.04 KB

File metadata and controls

66 lines (56 loc) · 2.04 KB
toc false
comments true
layout base
title Question Runtime
author Rachit
permalink /qrt

Question Runtime

Fetch Data

<script> document.getElementById('fetchButton').addEventListener('click', function() { const baseURL = "https://codemaxxerbackend.onrender.com/api/questions/course"; const course = "csa"; // Replace with the actual course value const url = `${baseURL}/${course}`; fetch(url, { method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }) .then(data => { // Create a table let table = ""; // Insert data into the table data.forEach(item => { table += ``; }); table += "
IDQuestionAnswer 1Answer 2Answer 3Answer 4Correct AnswerDifficultyUnitPoints
${item.id} ${item.question} ${item.answer1} ${item.answer2} ${item.answer3} ${item.answer4} ${item.correctAnswer} ${item.difficulty} ${item.unit} ${item.points}
"; // Display the table document.getElementById('result').innerHTML = table; }) .catch(error => { console.error('There has been a problem with your fetch operation:', error); document.getElementById('result').textContent = 'Error: ' + error.message; }); }); </script>