#how to run code in the terminal?

58 messages · Page 1 of 1 (latest)

royal sparrow
#

heres the script if its related to what i typed

#

not script ,coder

#

code

#

how to run terminal?

#

how to run code in the terminal?

polar dirge
#

How are you running it?

royal sparrow
#

i was running it previously with debug console until i realized it was the debug console and not the terminal

polar dirge
#

node function.js

royal sparrow
#

same thing

polar dirge
#

Is that path correct? Does the file exist? Did you save it?

#

Path doesn’t look correct

royal sparrow
polar dirge
#

You’re in your “home” directory, not desktop (in the terminal)

royal sparrow
#

how do i change that?]

#

replace user ptar with desktop?

polar dirge
#
cd C:\Users\ptara\Desktop\html\ and\ java\
node function.js
royal sparrow
#

ohh is there a backslash between spaces??

polar dirge
#

yes. it's called an escape character. you'll run into it a lot

royal sparrow
#

okokokok

#

yea no taht dont worj

#

work

polar dirge
#

hah. I fail. use quotes

royal sparrow
#

where

polar dirge
#
cd "C:\Users\ptara\Desktop\html and java"
node function.js
royal sparrow
#

ahh alr

#

why are the quotes needed?

polar dirge
#

makes the entire string (including spaces) a single argument

royal sparrow
#

it makes it 1 string basically or no?

polar dirge
#

yes. there's only a single argument, instead of argument 1 being C:\Users\ptara\Desktop\html, argument 2 being and, and argument 3 being java

#

P.S.:

tardy ospreyBOT
#

Despite their similarity in name, Java and JavaScript are different languages and are not compatible with each other. This is a JavaScript server, but there are likely many Java-specific servers out there.

royal sparrow
#

alr thanks now i need to figure out why my function isnt returning

royal sparrow
#

like with every new project and with every time i want to run the code?

heady lichen
#

You just need to be in directory where your .js file is. Which is what you've done with cd {path to directory. This sets which folder aka directory you are in, in your cmd. Since you are in folder where your js file is. Node is able to find it and run it

polar dirge
#

Typically you open that folder in vscode so it sets the path when you open a terminal.

royal sparrow
#

yea i found out whilst messing with the explorer

polar dirge
royal sparrow
#

so it doesnt display the number 20?

#

but it returns it

polar dirge
#

Right. console.log() to display

royal sparrow
#

on other editors it would show the 20? or is this a feature that isnt in vscode

polar dirge
#

That’s DevTools console

#

Like it showed undefined for the previous line, it always shows the return value of that expression

heady lichen
#

return of your function function1() is number '20'. But you or we can't see any of that because once you run your .js file with node, your program successfully runs but it doesn't output anything to the console. That's why you need use 'console.log() to log a output to a console.

royal sparrow
#

so its there but its not showing?

polar dirge
#

Yes. The return value of the function is 20

#

Assign it to a variable, log it, do whatever you want with it. But do something..

royal sparrow
#

how would i make it visible in terminal? console.log(function1) ?. ( idk how to type in the code way)

heady lichen
#

Your almost there. I recommend you keep experimenting with your code.

royal sparrow
#

u spent that whole time typing just to say that 😭 . i was hoping you would tell me lol. i will be experimenting

heady lichen
#

I was about to tell you what you needed to type but figured you'd need to do this on your own.

royal sparrow
#

yea i realized that i needed to log the return otput

#

if thats how u would say it

#

(function1())

heady lichen
#

Anyways. Good luck on your JavaScript learning journey. It's a great journey and I hope you keep at it