0% found this document useful (0 votes)
5 views1 page

Code

The document outlines a JavaScript code snippet for managing a scoring system in a webcam application. It initializes high and last scores from cookies, updates the display, and handles score saving when the camera is stopped. Additionally, it resets various variables and stops the video stream when the scoring process is completed.

Uploaded by

ivrhowjb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Code

The document outlines a JavaScript code snippet for managing a scoring system in a webcam application. It initializes high and last scores from cookies, updates the display, and handles score saving when the camera is stopped. Additionally, it resets various variables and stops the video stream when the scoring process is completed.

Uploaded by

ivrhowjb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

// In your initialization:

let highScore = Number(getCookie("highscore")) || 0;


let lastScore = Number(getCookie("lastscore")) || 0; // Changed from "score" to avoid confusion

// Update displays
lScoreDisplay.textContent = lastScore;
hScoreDisplay.textContent = highScore;

// In your stopCamera function:


function stopCamera() {
webcamRunning = false;
startButton.disabled = false;
stopButton.disabled = true;

const roundedScore = Math.round(score);

// Update high score if current score is higher


if (roundedScore > highScore) {
highScore = roundedScore;
setCookie("highscore", highScore, 365);
hScoreDisplay.textContent = highScore;
}

// Always update last score


lastScore = roundedScore;
setCookie("lastscore", lastScore, 365);
lScoreDisplay.textContent = lastScore;

Swal.fire({
title: "Score saved!",
icon: "success",
});

// Reset other variables


leftElbowAngleDisplay.textContent = 0;
score = 0;
scoreDisplay.textContent = score;
startScore = false;
angleArray.length = 0;

// Stop video stream


if (videoElement.srcObject) {
const stream = videoElement.srcObject;
if (stream instanceof MediaStream) {
stream.getTracks().forEach(track => track.stop());
}
videoElement.srcObject = null;
}

canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);


}

You might also like