Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Arrays Multidimensional Arrays Improve the Quiz – One Solution

Guido Greco
Guido Greco
9,361 Points

How could I add the .toLowerCase for the answers?

How could I add the .toLowerCase for the answers?

2 Answers

Hi, Guido Greco. Here is my solution since this condition statement is used to check user's responses, so I added the .toLowerCase() after the word "response" and "answer".

 if ( response.toLowerCase() === answer.toLowerCase()) {
    correctAnswers++;
    correct.push(question);

Hey there,

The .toLowerCase() is a method used on strings.

To call this method, take this example:

var someVariable = "HEY I AM A STRING";

someVariable.toLowerCase();

// Will return: hey i am a string
Guido Greco
Guido Greco
9,361 Points

Hey furkan thank you for the answer. But, I thought the question was linked to the work I was doing. Here is the code that I am trying to do with .toLowerCase

const questions = [
  ['Cuantos paises limitan con Argentina?','5'],
  ['Bebida comun en Argentina?','mate'],
  ['Color de la franja del medio de la bandera de Argentina','blanca'],
  ['Cuantos planetas hay en el Sistema Solar?','8']
]


const correct = [];
const incorrect = [];
let correctAnswers = 0

for (let i = 0; i < questions.length; i++) {
  let question = questions[i][0];
  let answer = questions[i][1];
  let response = prompt (question);


  if ( response === answer) {
    correctAnswers++;
    correct.push(question);


  } else {
    incorrect.push(question);
  }
}

function createListItems(arr) {
  let items = '';
  for (let i = 0; i < arr.length; i++) {
    items += `<li>${arr[i]}</li>`;
  }
  return items;
}

let html = `
<h1>You got ${correctAnswers} questions</h1>
<h2>You got these questions right</h2>
<ol>${createListItems(correct)}</ol>

<h2>You got these questions wrong:</h2>
<ol>${createListItems(incorrect)}</ol>
`;



document.querySelector('main').innerHTML = html;

Thank you in advance!