Ignacio's Capstone

AP CREATE

2A)

My program is written using JavaScript and the Jquery library. My code was created by using the Glitch development program. The purpose of my trivia game is for you to gain knowledge about the Mexican Revolution. In this video clip, you can see how the trivia game functions when the game is in action.The questions in the trivia are questions that have some connection with the Mexican Revolution and help you gain some knowledge about the Mexican Revolution.

2B)

My partner and I used iterative pair programming by my partner typing half of the Javascript code and then me typing the other half of the code .The first developmental challenge I encountered was not being able to make the questions show on the screen. I solved this challenge by breaking the code into pieces which made our code be more clear since I had named some of my functions the same name which made me get confused and totally made my code not work as intended. The second developmental challenge I encountered was when you tried answering the last question you wouldn't get your score and it would just keep staying on the last question. I solved this challenge by adding an extra curly bracket and removing a semicolon that was not needed. By myself, I was able to make the trivia game a multiple answer trivia game. My partner and I overcame a challenge by revising the code every time something was not functioning since it could have messed up all of our code which it did sometimes but we fixed it as fast as we were able to.

2C)

let answer = selectedOption.value;
    if (questions[currentQuestion].answer == answer) {
        score += 10;
    }

My main algorithm that I am using is the function showNewQuestion(). Inside the function showNewQuestion() each question is worth 10 points, if the user selects the answer give them 10 points since the answer equals the selectedOption. This sub algorithm is adding 10 points each time you choose the correct answer which at the end it will give you your final score.The showNewQuestion() function incorporates a math sub algorithm as shown below.


                    
                
The purpose of this code is so you can get your score after you respond all the trivia questions. When this logic algorithm runs correctly it will show “Your score is 60 out of 80” at the end of the game. The algorithm is able to achieve this because it is using the resultCont.textContent to display your final score. If this program did not include this algorithm, then you will not be able to view your final score and you will not know if you did good or bad on the trivia. The function showNewQuestion() also incorporates a logic sub algorithm as shown.
if (currentQuestion == totalQuestions) {
        container.style.display = "none";
        resultCont.style.display = "";
        resultCont.textContent = "Your Score is " + score + " out of 80";
        return;
    }
The intended purpose of this sub algorithm is to reset the hail that has fallen out of the canvas to make the hail continue falling. When this logic algorithm shown above runs correctly it is able to make the hail reset once it leaves the canvas width and go back right up. This sub algorithm is able to achieve this result because the if statement is telling the circles that are out of the screen to choose different x-postions and reset the y-position to zero if they are out of the canvas height.

2D)

function showNewQuestion() {
    let selectedOption = document.querySelector("input[type=radio]:checked");
    if (!selectedOption) {
        alert("Please choose your answer!");
        return;
    }
    let answer = selectedOption.value;
    if (questions[currentQuestion].answer == answer) {
        score += 10;
    }
    selectedOption.checked = false;
    currentQuestion++;
    if (currentQuestion == totalQuestions - 1) {
        newButton.textContent = "Finish";
    }
    if (currentQuestion == totalQuestions) {
        container.style.display = "none";
        resultCont.style.display = "";
        resultCont.textContent = "Your Score is " + score + " out of 80";
        return;
    }
    loadQuestion(currentQuestion);
}
 
loadQuestion(currentQuestion);

An example of an abstraction in my program is the showNewQuestion function. This simplifies my program by making the project function without extra code that is not useful to the project. I created this function to avoid the problem of not being able to finish the trivia game.If this abstraction weren’t present, you could not choose an answer then it wouldn't show an alert saying to choose an answer or show a button that takes you to the end of the game and it would not show your final score nor it would give each the score for the questions that that you got correct.