|
|
|
let currentTaskIndex = 0; |
|
let totalTasks = 5; |
|
let tasks = []; |
|
let reward = ""; |
|
|
|
|
|
document.addEventListener("DOMContentLoaded", () => { |
|
const rootElem = document.getElementById("rootelm"); |
|
const alpineComponent = { |
|
data: { |
|
currentTaskIndex, |
|
totalTasks, |
|
tasks, |
|
reward |
|
}, |
|
methods: { |
|
|
|
} |
|
}; |
|
Alpine.store(alpineComponent); |
|
const alpine = new Alpine(rootElem, alpineComponent); |
|
Alpine.start(); |
|
alpineComponent.$watch("reward", (newValue) => { |
|
reward = newValue; |
|
}); |
|
}); |
|
|
|
|
|
function addTask(title, description, reward) { |
|
tasks.push({ |
|
title, |
|
description, |
|
reward |
|
}); |
|
currentTaskIndex++; |
|
} |
|
|
|
|
|
function completeTasks() { |
|
Alpine.store(alpineComponent); |
|
Alpine.start(); |
|
} |
|
|
|
|
|
function rewardUser() { |
|
Alpine.store(alpineComponent); |
|
Alpine.start(); |
|
} |
|
|
|
|
|
function playRickRoll() { |
|
const audio = new Audio(); |
|
audio.src = "https://www.soundjay.com/pack-oregondave-rick.mp3"; |
|
audio.play(); |
|
} |
|
|
|
|
|
addTask("Do a chore", "Clean your room", "You get a dollar"); |
|
addTask("Watch a video", "Watch a funny cat video", "You get a candy"); |
|
addTask("Complete a task", "Complete a task", "You get a toy"); |
|
|
|
|
|
completeTasks(); |
|
rewardUser(); |
|
playRickRoll(); |