skip to Main Content

Good day!

I am taking the javascript basics course on treehouse. I am brand new to this learning processes.

I have included all of my javascript code and the directions at the bottom. I am making a basic quiz acrewing the correct number of answers and awarding a "crown" at the end that indicates the level of success.

Since starting this course I have went back and taken the html and css course. I will do things differently in the future. But I have spend so much time on this project I NEED to make it work.

Thank you for your time.

My intention is to utilize the else if statement to determine the response according to how many questions are correct. I have started by just trying to utilize the if else statement for the first part of the solution and I can not get the condition to state the false response. I figured after I get this correct I can create the else if statements.

const me = prompt('n What is your name?n');

const greating = alert(`n Good day ${me}! nnThis is a quiz about Apis mellifera.  Increase your rank by answering correctly.`);

let record = 0;

alert(`n Correct Answers: ${record}`);


const one = prompt('n 1. Apis mellifera is the scientific name for what non-native insect?n');
if (one.toUpperCase() === 'european honeybee'.toUpperCase() || one.toUpperCase() === 'honeybee'.toUpperCase() 
|| one.toUpperCase() === 'bee'.toUpperCase() || one.toUpperCase() === 'european honey bee'.toUpperCase() 
|| one.toUpperCase() === 'honey bee'.toUpperCase()) 

{ alert('n That is correct!!')
  alert(`n Correct Answers: ${record += 1}`)
} 
  else alert('n This is NOT correct.')
{ alert(`n Correct Answers: ${record += 0}`)
}

const two = prompt('n 2. Name one of the three types of adult European honeybees in a colony?n');
if (two.toUpperCase() === 'queen'.toUpperCase() || two.toUpperCase() === 'queens'.toUpperCase() ||
    two.toUpperCase() === 'drone'.toUpperCase() || two.toUpperCase() === 'drones'.toUpperCase() ||
    two.toUpperCase() === 'worker'.toUpperCase() || two.toUpperCase() === 'workers'.toUpperCase()) 
{ alert('n That is correct!!')
  alert(`n Correct Answers: ${record += 1}`)
}
  else alert('n This is NOT correct.')
{ alert(`n Correct Answers: ${record += 0}`)
}

const three = prompt('n 3. How does the queen communicate with her colony?n');
if (three.toUpperCase() === 'pheromones'.toUpperCase() || three.toUpperCase() === 'scent'.toUpperCase() ||
    three.toUpperCase() === 'chemicals'.toUpperCase() || three.toUpperCase() === 'her musk'.toUpperCase()) 
{ alert('n That is correct!!')
  alert(`n Correct Answers: ${record += 1}`)
} 
  else alert('n This is NOT correct.')
{ alert(`n Correct Answers: ${record += 0}`)
}

const four = prompt('n 4. How do worker bees tell other workers where to find food sources?n');
if (four.toUpperCase() === 'waggle dance'.toUpperCase() || four.toUpperCase() === 'dance'.toUpperCase() ||
    four.toUpperCase() === 'dancing'.toUpperCase() || four.toUpperCase() === 'wiggling her tukas'.toUpperCase()) 
{ alert('n That is correct!!')
  alert(`n Correct Answers: ${record += 1}`)
} 
  else alert('n This is NOT correct.')
{ alert(`n Correct Answers: ${record += 0}`)
}

const five = prompt('n 5. What is the name of the mite that is desicrating the Apis mellifera population?n');
if (five.toUpperCase() === 'Veroa destructor'.toUpperCase() || five.toUpperCase() === 'Veroa'.toUpperCase() ||
    five.toUpperCase() === 'blood sucking, virus carrying bastards'.toUpperCase()) 
{ alert('n That is correct!!')
  alert(`n Correct Answers: ${record += 1}`)
} 
  else alert('n This is NOT correct.')
{ alert(`n Correct Answers: ${record += 0}`)
}

alert(`n Total Correct Answers: ${record}`)

if (`${record} == 5`)
 { alert('n Congratulations!  You got them all right.  You award is the gold crown. You are the Queen Bee!')
 } else
 { alert('n The bees need you to do better.')
 }


/*
0.0 directions 
  1. Store correct answers
   - When quiz begins, no answers are correct
*/


// 2. Store the rank of a player


// 3. Select the <main> HTML element

/*<p>
  
  </p>
*/

/*
  4. Ask at least 5 questions
   - Store each answer in a variable
   - Keep track of the number of correct answers
*/

/*   1.  Apis mellifera is the scientific name for what non-native insect?
    2.  A European honeybee consists of what three types of adult bees?
    3.  How does the quess communicate with her colony?
    4.  How do worker bees tell other workers where to find food sources?
    5  What is the name of the mite that is desicrating the Apis mellifera population?
*/    
/*
  5. Rank player based on number of correct answers
   - 5 correct = Gold
   - 3-4 correct = Silver
   - 1-2 correct = Bronze
   - 0 correct = No crown
*/


// 6. Output results to the <main> element

I saw some people put semicolons in their if else and else if statements. I tried that.

I tried researching the internet for solutions. I think maybe I don’t know the correct questions to ask.

I honestly don’t remember what all I’ve tried. I wanted to figure it out on my own but have waisted so much time on it I figured it was time to reach out for help.

I have tried to review the previous questions to see if they are applicable to me…but I am to ignorant to know if they are the same as my situaiton.

I have no doubt the answer is going to be foolishly simple. Thank you for your time.

Magan

2

Answers


  1. const me = prompt('n What is your name?n');
    const greeting = alert(`n Good day ${me}! nnThis is a quiz about Apis mellifera.  Increase your rank by answering correctly.`);
    let record = 0;
    alert(`n Correct Answers: ${record}`);
    
    const questions = [
      {
        question: 'n 1. Apis mellifera is the scientific name for what non-native insect?n',
        answer: ['european honeybee', 'honeybee', 'bee', 'european honey bee', 'honey bee']
      },
      {
        question: 'n 2. Name one of the three types of adult European honeybees in a colony?n',
        answer: ['queen', 'queens', 'drone', 'drones', 'worker', 'workers']
      },
      {
        question: 'n 3. How does the queen communicate with her colony?n',
        answer: ['pheromones', 'scent', 'chemicals', 'her musk']
      },
      {
        question: 'n 4. How do worker bees tell other workers where to find food sources?n',
        answer: ['waggle dance', 'dance', 'dancing', 'wiggling her tukas']
      },
      {
        question: 'n 5. What is the name of the mite that is desicrating the Apis mellifera population?n',
        answer: ['Veroa destructor', 'Veroa', 'blood sucking, virus carrying bastards']
      }
    ];
    
    questions.forEach((question, index) => {
      const userAnswer = prompt(question.question).toLowerCase();
      if (question.answer.includes(userAnswer)) {
        alert('n That is correct!!');
        record++;
      } else {
        alert('n This is NOT correct.');
      }
    });
    
    alert(`n Total Correct Answers: ${record}`);
    
    if (record === 5) {
      alert('n Congratulations!  You got them all right.  You award is the gold crown. You are the Queen Bee!')
    } else {
      alert('n The bees need you to do better.')
    }
    const me = prompt('n What is your name?n');
    const greeting = alert(`n Good day ${me}! nnThis is a quiz about Apis mellifera.  Increase your rank by answering correctly.`);
    let record = 0;
    alert(`n Correct Answers: ${record}`);
    
    const questions = [
      {
        question: 'n 1. Apis mellifera is the scientific name for what non-native insect?n',
        answer: ['european honeybee', 'honeybee', 'bee', 'european honey bee', 'honey bee']
      },
      {
        question: 'n 2. Name one of the three types of adult European honeybees in a colony?n',
        answer: ['queen', 'queens', 'drone', 'drones', 'worker', 'workers']
      },
      {
        question: 'n 3. How does the queen communicate with her colony?n',
        answer: ['pheromones', 'scent', 'chemicals', 'her musk']
      },
      {
        question: 'n 4. How do worker bees tell other workers where to find food sources?n',
        answer: ['waggle dance', 'dance', 'dancing', 'wiggling her tukas']
      },
      {
        question: 'n 5. What is the name of the mite that is desicrating the Apis mellifera population?n',
        answer: ['Veroa destructor', 'Veroa', 'blood sucking, virus carrying bastards']
      }
    ];
    
    questions.forEach((question, index) => {
      const userAnswer = prompt(question.question).toLowerCase();
      if (question.answer.includes(userAnswer)) {
        alert('n That is correct!!');
        record++;
      } else {
        alert('n This is NOT correct.');
      }
    });
    
    alert(`n Total Correct Answers: ${record}`);
    
    if (record === 5) {
      alert('n Congratulations!  You got them all right.  You award is the gold crown. You are the Queen Bee!')
    } else {
      alert('n The bees need you to do better.')
    }
    Login or Signup to reply.
  2. Just store the final score as a variable as shown below:

    const final = `${record}`
    
    if (final == 5)
     { alert('n Congratulations!  You got them all right.  You award is the gold crown. You are the Queen Bee!')
     } else
     { alert('n The bees need you to do better.')
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search