Question on web dev 101: javascript fundamentals 3 - can I use a string without quotes?

So I have a solution to this question, but I was trying to call the function capitalize(words)
as capitalize(SOME RANDOM PHRASE) but it doesn’t work.

I even tried changing the argument to a phrase like “let stringer = words.string” but it still failed.

Is that because if I call a function on a string argument without quotes, it’s perceived as a variable?

Thanks!


Write a function called capitalize that takes a string and returns that string with only the first letter capitalized. Make sure that it can take strings that are lowercase, UPPERCASE or BoTh.

function capitalize(words) {
let newString = words.toLowerCase();
let firstLetter = newString.slice(0,1);
let fixedString = newString.replace(firstLetter,firstLetter.toUpperCase());
console.log(fixedString);
}

let words = prompt(‘gimme phrase’);

capitalize(words)

Is that because if I call a function on a string argument without quotes, it’s perceived as a variable

Either you call it without quotes on a variable that is a string itself capitalize(variableName) or you call it directly with quotes on your string capitalize('Hello World!').
In your example, if you don’t use quotes, the compiler is lost because it’s like if you invoke a variable SOME followed by spaces and further characters.

Cool, I think I got it – thank you!