6

learning JS, first time using netbeans.My code can compile, but i don't know how to print to the console screen. I've tried the system.out.println function, but that still doesn't work. What am I doing wrong?

enter image description here

EDIT: This question is different because i've never actually seen these functions used before. At all the other programs i've used online, the output was automatic, so to add "console.log()....where do i put it, and how do i make it show the values of the variables like in the text?

Sloan Brown
  • 185
  • 1
  • 1
  • 4
  • 9
    `What am I doing wrong?` you're coming here before googling this basic javascript function – user1231232141214124 Jan 12 '16 at 00:17
  • 2
    Possible duplicate of [JavaScript: How do I print a message to the error console?](http://stackoverflow.com/questions/164397/javascript-how-do-i-print-a-message-to-the-error-console) –  Jan 12 '16 at 00:21
  • 1
    That does look very like Resig stuff. Are you from Khanacademy? Methods like fill & textSize are not native in javascript. It's a part of a library. – Fella Jan 12 '16 at 00:23
  • 2
    @Fella what difference does that make to the question asked? Please don't add irrelevant noise as comments – charlietfl Jan 12 '16 at 00:29
  • seriously why don't you take a book about javascript and learn from there? There are a bunch of them accessible even for free. Or search for similar question on stackoverflow ? Show some effort if you want other people to help you. – user3743222 Jan 12 '16 at 00:48
  • ok guys, i get it, problem is there is no question here that shows me how i actually USE the javascript!= function. EX: Where do I put it? Do I put Javascript != { and then code? or....what? I've never used it so, maybe i'm nuking it, but i'm trying to use it and It's not working.....neither it nor the console.log is not working because i have no idea how to use those things. – Sloan Brown Jan 12 '16 at 00:49
  • I've tried googling it, nothing helpful shows up, and the closest library is 40 miles away. – Sloan Brown Jan 12 '16 at 00:49
  • @SloanBrown `Javascript !=` was not an answer to your question ... and still laughing at your `closest library is 40 miles away` ... classic!!! – Jaromanda X Jan 12 '16 at 01:18

2 Answers2

18

That looks like you're confusing Javascript with Java. They're not the same language. NetBeans is a development environment for Java, not Javascript. But to answer your main question, to print to the console in JavaScript, you can use the function console.log() like this.

    console.log(text);

In your case, you could write

    console.log("Obama is " + obama.age + " years old.");
uniqueusername
  • 388
  • 3
  • 9
  • You're right, i figured this out myself a long time ago. Thanks guys. Part of being 25 years old being brand new to coding at all. – Sloan Brown Jan 26 '16 at 22:50
  • 3
    @SloanBrown You might want to mark this answer as accepted answer if it solved your problem. This helps the community to focus on unanswered questions. You will have to click the grey check mark below the voting buttons to mark it as accepted answer. – RBT May 31 '18 at 09:11
10

Use console.log("some text") to print the text

(or)

If you want to print the value stored in the variable then you can give the variable name inside the console.log()

e.g.

var text = "some text"
console.log(text)
Manikandan C
  • 652
  • 9
  • 18