0

I'm making a prompt that's supposed to capitalize user input and print it into the HTML. But it won't capitalize the input, what am I doing wrong?

var name = prompt("What's your name?");
var fullname = name;

function capitalize() {
    fullname.style.textTransform = "capitalize";
}
document.write(fullname);
Jamiec
  • 128,537
  • 12
  • 134
  • 188
wnordqvist
  • 29
  • 2
  • 1
    You're trying to invoke the `style` property of a variable? It won't work unless that variable points to an HTML element or is an object with a property named `style`. You might be getting an exception on your browser console. – emerson.marini Oct 12 '20 at 11:44
  • possible duplicate of https://stackoverflow.com/questions/5927012/javascript-createelement-style-problem – raju Oct 12 '20 at 11:54

2 Answers2

3

Aside from he fact that you never call your capitalize method, fullname is just a string. style.textTransform is how you might set the style properties of an HTML element.

var name = prompt("What's your name?");
var elem = document.querySelector('#output');
elem.style.textTransform = "capitalize";
elem.innerText = name;
<div id="output"></div>
Jamiec
  • 128,537
  • 12
  • 134
  • 188
0

It's not capitalize, it's uppercase.

var name = prompt("What's your name?");
var elem = document.querySelector('#output');
elem.style.textTransform = "uppercase";
elem.innerText = name;
<div id="output"></div>
barhatsor
  • 1,635
  • 5
  • 19