I have done a randomly generated quote generator using math.random shown and I want to be able to have a like button that is able to collect all of the liked quotes into another array so it can be able to be displayed inside of another popup box. So this is what I have so far with a checkbox button inside of my array an object named like
var quotes = [
{verses: "This is my first quote", chapter: "Psalm 139:7-10", data: "Never be Lost", id: "like1", like: '<input type="checkbox" name="like" id="like1"><label for="like1"><img src="not_liked.svg" alt="Wanna Like It? " width="16"></label>'},
{verses: "This is my second quote", chapter: "Matthew 27:32-44", data: "The Crucifixion of Jesus", id: "like2", like: '<input type="checkbox" name="like" id="like2"><label for="like1"><img src="not_liked.svg" alt="Wanna Like It? " width="16"></label>'},]$(document).ready(function () {
console.log(likedVerses);
function showQuote () {
var init = Object.keys(quotes);
var rng = init[Math.floor(Math.random()*init.length)];
$('.quote').html(quotes[rng].verses);
$('.name').html(quotes[rng].chapter);
$('.meaning').html(quotes[rng].data);
$('.like').html(quotes[rng].like);
}});
Then I added a for loop looping through the array inside of my document.ready function
$("input[type='checkbox']").click(function () {
for (var i = 0; i < quotes.length; i++){
if(quotes[i].id === this.id){
if ($(this).is(":not(:checked)")){
}
else {
likedVerses.push(quotes[i])
}
break;
}
}
Basically I would like to have a checkbox that is assigned to each randomly generated quote and when it's checked, it'll store the objects into an array. I would really appreciate the help.