Is there any way to reduce this?
//vars
defaultTextColor="#444"
correct = "#99CC00"
incorrect = "#FF4719"
answer1value = "1"
answer2value = "3"
totalquestions= "5"
//tap on the words
$(function() {
$("#word1a").click(function() {
$("#word1b").css("text-decoration", "line-through").css("opacity", "0.2").css("color", defaultTextColor);
$("#word1a").css("text-decoration", "none").css("opacity", "1").css("color", defaultTextColor);
$("#slash1").css("text-decoration", "line-through").css("opacity", "0.1");
saveanswers();
});
$("#word1b").click(function() {
$("#word1b").css("text-decoration", "none").css("opacity", "1").css("color", defaultTextColor);
$("#word1a").css("text-decoration", "line-through").css("opacity", "0.2").css("color", defaultTextColor);
$("#slash1").css("text-decoration", "line-through").css("opacity", "0.1")
saveanswers();
});
$("#word2a").click(function() {
$("#word2b").css("text-decoration", "line-through").css("opacity", "0.2").css("color", defaultTextColor);
$("#word2a").css("text-decoration", "none").css("opacity", "1").css("color", defaultTextColor);
$("#slash2").css("text-decoration", "line-through").css("opacity", "0.1");
saveanswers();
});
$("#word2b").click(function() {
$("#word2b").css("text-decoration", "none").css("opacity", "1").css("color", defaultTextColor);
$("#word2a").css("text-decoration", "line-through").css("opacity", "0.2").css("color", defaultTextColor);
$("#slash2").css("text-decoration", "line-through").css("opacity", "0.1")
saveanswers();
});
$("#word3a").click(function() {
$("#word3b").css("text-decoration", "line-through").css("opacity", "0.2").css("color", defaultTextColor);
$("#word3a").css("text-decoration", "none").css("opacity", "1").css("color", defaultTextColor);
$("#slash3").css("text-decoration", "line-through").css("opacity", "0.1");
saveanswers();
});
$("#word3b").click(function() {
$("#word3b").css("text-decoration", "none").css("opacity", "1").css("color", defaultTextColor);
$("#word3a").css("text-decoration", "line-through").css("opacity", "0.2").css("color", defaultTextColor);
$("#slash3").css("text-decoration", "line-through").css("opacity", "0.1")
saveanswers();
});
});
//resets the inputs on change
$(function() {
$("#answer1").change(function() {
{$(this).css("background-color", "lightgrey").css("color", defaultTextColor)}
});
$("#answer2").change(function() {
{$(this).css("background-color", "lightgrey").css("color", defaultTextColor)}
});
});
//Save storage
function saveanswers() {
input1save = $('#answer1 option:selected').val()
localStorage['Physicsforyou-focustheeye-input1-6614-4506-8817-6439-3960'] = input1save
input2save = $('#answer2 option:selected').val()
localStorage['Physicsforyou-focustheeye-input2-4475-3759-7632-7863-3079'] = input2save
word1asave = $('#word1a').css("text-decoration")
localStorage['Physicsforyou-focustheeye-word1a-7790-2123-5352-3513-7817'] = word1asave
word1bsave = $('#word1b').css("text-decoration")
localStorage['Physicsforyou-focustheeye-word1b-4620-2663-8547-2077-6191'] = word1bsave
word2asave = $('#word2a').css("text-decoration")
localStorage['Physicsforyou-focustheeye-word2a-4176-8928-3185-6999-8057'] = word2asave
word2bsave = $('#word2b').css("text-decoration")
localStorage['Physicsforyou-focustheeye-word2b-5094-8829-5741-5172-3780'] = word2bsave
word3asave = $('#word3a').css("text-decoration")
localStorage['Physicsforyou-focustheeye-word3a-5294-2006-4289-2311-5537'] = word3asave
word3bsave = $('#word3b').css("text-decoration")
localStorage['Physicsforyou-focustheeye-word3b-5429-1989-1854-1009-7066'] = word3bsave
}
//Load storage
$( document ).ready(function() {
input1save = localStorage['Physicsforyou-focustheeye-input1-6614-4506-8817-6439-3960']
input2save = localStorage['Physicsforyou-focustheeye-input2-4475-3759-7632-7863-3079']
word1asave = localStorage['Physicsforyou-focustheeye-word1a-7790-2123-5352-3513-7817']
word1bsave = localStorage['Physicsforyou-focustheeye-word1b-4620-2663-8547-2077-6191']
word2asave = localStorage['Physicsforyou-focustheeye-word2a-4176-8928-3185-6999-8057']
word2bsave = localStorage['Physicsforyou-focustheeye-word2b-5094-8829-5741-5172-3780']
word3asave = localStorage['Physicsforyou-focustheeye-word3a-5294-2006-4289-2311-5537']
word3bsave = localStorage['Physicsforyou-focustheeye-word3b-5429-1989-1854-1009-7066']
tallyload = localStorage['Physicsforyou-focustheeye-tallyload-3405-1672-6158-8392-4746']
$('#answer1').val(input1save)
$('#answer2').val(input2save)
$('#tally').html(tallyload)
if (word1asave=="line-through")
{$('#word1a, #slash1').css("text-decoration", "line-through").css("opacity", "0.2")
}
if (word1bsave=="line-through")
{$('#word1b, #slash1').css("text-decoration", "line-through").css("opacity", "0.2")
}
if (word2asave=="line-through")
{$('#word2a, #slash2').css("text-decoration", "line-through").css("opacity", "0.2")
}
if (word2bsave=="line-through")
{$('#word2b, #slash2').css("text-decoration", "line-through").css("opacity", "0.2")
}
if (word3asave=="line-through")
{$('#word3a, #slash3').css("text-decoration", "line-through").css("opacity", "0.2")
}
if (word3bsave=="line-through")
{$('#word3b, #slash3').css("text-decoration", "line-through").css("opacity", "0.2")
}
});
//Check Answers
$(function() {
$("#checkanswers").click(function() {
input1 = $('#answer1 option:selected').val();
input2 = $('#answer2 option:selected').val();
score=0
if (input1==answer1value)
{
$('#answer1').css("background-color", correct).css("color", "white");
score++
}
else
{
$('#answer1').css("background-color", incorrect).css("color", "white");
}
if (input2==answer2value)
{
$('#answer2').css("background-color", correct).css("color", "white");
score++
}
else
{
$('#answer2').css("background-color", incorrect).css("color", "white");
}
if ($('#word1a').css("text-decoration") == 'line-through')
{
$('#word1b').css("color", correct);
score++
}
if ($('#word1b').css("text-decoration") == 'line-through')
{
$('#word1a').css("color", incorrect);
}
if ($('#word2a').css("text-decoration") == 'line-through')
{
$('#word2b').css("color", correct);
score++
}
if ($('#word2b').css("text-decoration") == 'line-through')
{
$('#word2a').css("color", incorrect);
}
if ($('#word3a').css("text-decoration") == 'line-through')
{
$('#word3b').css("color", correct);
score++
}
if ($('#word3b').css("text-decoration") == 'line-through')
{
$('#word3a').css("color", incorrect);
}
finalscore= Math.round(score/totalquestions*100)
$('#tally').html("You scored " + score + "/" + totalquestions + " - " + finalscore + "%");
tallysave = "You scored " + score + "/" + totalquestions + " - " + finalscore + "%"
localStorage['Physicsforyou-focustheeye-tallyload-3405-1672-6158-8392-4746'] = tallysave
tallylog = finalscore
localStorage['Physicsforyou-focustheeye-tallylog-7600-5956-8912-6767-3256'] = tallylog
});
});
//clear answers
$(function() {
$("#clearanswers").click(function() {
$('#answer1').val("0")
$('#answer2').val("0")
$('#answer1, #answer2').css("background-color", "lightgrey").css("color", "black");
$("#word1a, #word1b, #slash1, #word2a, #word2b, #slash2, #word3a, #word3b, #slash3").css("text-decoration", "none").css("opacity", "1").css("color", defaultTextColor)
saveanswers();
});
});
//Thumbs Load
$(document).ready(function () {
if (localStorage.getItem('Physicsforyou-focustheeye-thumbs-3747-4345-2469-7020-2251') === 'up') {
thumbsup();
}
else if (localStorage.getItem('Physicsforyou-focustheeye-thumbs-3747-4345-2469-7020-2251') === 'down') {
thumbsdown();
}
});
//Thumbs Save
function thumbsup() {
$("#thumbsdown").removeClass("btn-danger").addClass("btn-default");
$("#thumbsup").removeClass("btn-default").addClass("btn-success");
localStorage.setItem('Physicsforyou-focustheeye-thumbs-3747-4345-2469-7020-2251', 'up');
}
function thumbsdown() {
$("#thumbsdown").removeClass("btn-default").addClass("btn-danger");
$("#thumbsup").removeClass("btn-success").addClass("btn-default");
localStorage.setItem('Physicsforyou-focustheeye-thumbs-3747-4345-2469-7020-2251', 'down');
}