Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Mihai-Ady Zvancu
7,657 PointsWhy does my .toLowerCase() function NOT work inside the for loop?
The .toLowerCase() function in the following code is not working? Why is this happening?
function print(message) { document.write(message); }
let qa = [
["What is the speed of light (in km/s)?","300000"],
["What is the third closest planet to the Sun?","earth"],
["When did the Second World War end","1945"]
];
let html_1 = "; let html_2 = "; let corr_ans = 0; let answer;
for (let i = 0; i<qa.length; i++){
answer = prompt (qa[i][0]);
answer.toLowerCase();
console.log(answer); // I have put this line of code to see if .toLowerCase() function works
if (answer === qa[i][1]){
html_1 += "<li>"+qa[i][0]+"</li>";
corr_ans++;
}else{
html_2 += "<li>"+qa[i][0]+"</li>";
}
}
print("<h2>You answered "+corr_ans+" question(s) correctly!");
print("<ol>Questions with correct answer: "+html_1+"</ol>")
print("<ol>Questions with incorrect answer: "+html_2+"</ol>");
2 Answers

Zimri Leijen
11,760 PointsNote: The toLowerCase() method does not change the original string.
Basically, toLowerCase()
makes a lowercase COPY of the string.
If you don't overwrite the original string with the copy, or use the copy somewhere, then it doesn't really do anything.
So instead of
answer.toLowerCase()
you can do
answer = answer.toLowerCase()
// alternatively
const lowerCaseAnswer = answer.toLowerCase();

Mihai-Ady Zvancu
7,657 PointsThank you, all!
Caroline Forslund
Front End Web Development Techdegree Graduate 36,096 PointsCaroline Forslund
Front End Web Development Techdegree Graduate 36,096 PointsTiy would have to do something like this to save the lowercase change: