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

Gwen H
Gwen H
3,730 Points

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()) {

Hey there,

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

To call this method, take this example:

var someVariable = "HEY I AM A STRING";


// 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) {

  } else {

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>

<h2>You got these questions wrong:</h2>

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

Thank you in advance!