0

javascript toLowerCase()

question: why is here the right answer „Daveoxford“ and NOT „daveoxford“? var name = „Dave“; var school = „Oxford“; name.toLowerCase(); school.toLowerCase(); console.log(name + school); //the „“ in the code are both up. just dont know why this is here not working. 😒

19th Feb 2020, 3:57 PM
Mylisa_beth
Mylisa_beth - avatar
7 ответов
+ 6
You have to save the value in a variable. For example var name = "Dave"; var school = "Oxford"; name =name.toLowerCase(); school=school.toLowerCase(); console.log(name +school);
19th Feb 2020, 4:02 PM
Cmurio
Cmurio - avatar
+ 4
You have to save the value in a variable. In your code you were printing the same variable but not the lowercase value
19th Feb 2020, 4:03 PM
Cmurio
Cmurio - avatar
+ 1
Strings are immutable in JavaScript so the toLowerCase() will not alter the actual string until and unless the change is assigned to the string itself. Try writing- name=name.toLowerCase(); school=school.toLowerCase();
19th Feb 2020, 4:03 PM
Avinesh
Avinesh - avatar
+ 1
Mylisa_beth read the first statement of my answer which tells the reason behind that behaviour.
19th Feb 2020, 4:13 PM
Avinesh
Avinesh - avatar
+ 1
thank you folks!!! 👏👏👏💪💪💪
19th Feb 2020, 4:13 PM
Mylisa_beth
Mylisa_beth - avatar
0
You could also try console.log(name.toLowerCase());
19th Feb 2020, 4:12 PM
JaScript
JaScript - avatar