Cards Against Technophobes

Home » IT Services » Game
Cards Against TechnophobesV2

Cards Against Technophobes

Refresh the cards to get wacky and new combinations!

var lines, lines2, lines3; var randomNumber, randomNumber2, randomNumber3 = 0; var lastRandomNumber, lastRandomNumber2, lastRandomNumber3 = 0; function playSound(){ var sound = new Audio('sound/clickSound.mp3'); sound.play(); } function playShareSound(){ var shareSound = new Audio('sound/shareButtonSound.mp3'); shareSound.play(); } // function share(){ // shareButton.addEventListener('click', event => { // if (navigator.share) { // navigator.share({ // title:'ShareButton' // }).then(() => { // console.log('Thanks for sharing!'); // }) // .catch(console.error); // } else { // shareDialog.classList.add('is-open'); // } // }); // } // function closeShare(){ // closeButton.addEventListener('click', event => { // shareDialog.classList.remove('is-open'); // }); // } function getCardLines() { // Load black cards $.ajax({ url: 'cards/card.txt' }).done(function(content) { // normalize the line breaks, then split into lines lines = content.replace(/\r\n|\r/g, '\n').trim().split('\n'); getCardLines2(); getCardLines3(); }); } function getCardLines2() { // load white cards $.ajax({ url: 'cards/card2.txt' }).done(function(content2) { // normalize the line breaks, then split into lines lines2 = content2.replace(/\r\n|\r/g, '\n').trim().split('\n'); setupButton(); }); } function getCardLines3() { // load white cards $.ajax({ url: 'cards/card2.txt' }).done(function(content3) { // normalize the line breaks, then split into lines lines3 = content3.replace(/\r\n|\r/g, '\n').trim().split('\n'); setupButton(); }); } function setupButton() { // only set up the click handler if there were lines found if (lines && lines.length) { $('#btnDisplay').on('click', function () { //Card black 1 // loop to prevent repeating the last random number while (randomNumber === lastRandomNumber) { randomNumber = parseInt(Math.random() * lines.length); // check to prevent infinite loop if (lines.length === 1) { break; } } // keep track of the last random number lastRandomNumber = randomNumber; //Card white 2 while (randomNumber2 === lastRandomNumber2) { randomNumber2 = parseInt(Math.random() * lines2.length); // check to prevent infinite loop if (lines2.length === 1) { break; } } // keep track of the last random number lastRandomNumber2 = randomNumber2; //Card white 3 while (randomNumber3 === lastRandomNumber3) { randomNumber3 = parseInt(Math.random() * lines3.length); // check to prevent infinite loop if (lines3.length === 1) { break; } } // keep track of the last random number lastRandomNumber3 = randomNumber3; writeBlackCard(); writeWhiteCards(); displayWhiteCards(); }); } } function displayWhiteCards() { if(lines[randomNumber].includes("#2")) { document.getElementById("hideWhiteCard").style.display = "block"; document.getElementsByClassName("cardWhite2").style.display ="block"; } else { document.getElementById("hideWhiteCard").style.display = "none"; document.getElementsByClassName("cardWhite2").style.display ="none"; } } function writeBlackCard() { // show the corresponding line $('#blackCard').text(lines[randomNumber]); } function writeWhiteCards() { // show the corresponding line $('#whiteCard').text(lines2[randomNumber2]); $('#whiteCard2').text(lines3[randomNumber3]); } getCardLines(); //--------------------------------------------------------------// //---Web Share API---// //--------------------------------------------------------------// const shareBtn = document.querySelector('.share-btn'); const ogBtnContent = shareBtn.textContent; const title = document.querySelector('h1').textContent; const url = document.querySelector('link[rel=canonical]') && document.querySelector('link[rel=canonical]').href || window.location.href; shareBtn.addEventListener('click', () =>{ if(navigator.share){ navigator.share({ title, url }).then(() => { console.log(shareBtn, 'Thanks! 🙂 '); }) .catch(err => { console.log(shareBtn, 'Couldnt share 🙁 '); }); } else{ console.log(shareBtn, 'Not supported :O'); } }) function showMessage(element, msg){ element.textContent = msg; setTimeout(() => { element.textContent = ogBtnContent; }, 2000); }
Computer Assistance