0

very new to coding and decided to start a project of mine. I watched a video on how to get it set up and started but after tinkering with it a little, I realized it was Java, not JavaScript. (Hey, i'm a noob at this) and I wanted an easier way to implement new things. this is what my main script looks like.

public void onMessage(String Message){
if(message.equals("Apples"){
sendMessage("You said apples!")}
else { 
if(message.equals("Oranges" //any text 
){
    sendMessage("you said Oranges and" //what they put for any text
)
 ...

Is there a way to take the bit that says Oranges and replace it by calling a JS function from another file?

6
  • 2
    You should write code in the language you need. Commented Jun 27, 2016 at 20:36
  • 1
    do you want to write java or javascript ? Commented Jun 27, 2016 at 20:36
  • 2
    Your question doesn't make a lot of sense. You're either running Java or you're running JavaScript (at least at this stage). Just write your program in one language. Commented Jun 27, 2016 at 20:37
  • Don't be fooled by the names, Java and Javascript are two totally different languages. It is a quirk of marketing history that they sound similar. If you are new to programming, definitely you only want to learn one language at a time. Commented Jun 27, 2016 at 20:46
  • Oh, but to answer your question "Is there a way to take the bit that says Oranges and replace it by calling a JS function from another file?" the answer is yes, but this is an incredibly advanced technique for a beginning programmer, as most programming languages do not interoperate easily. Commented Jun 27, 2016 at 20:51

2 Answers 2

1

Java and javascript are two completely different things. Java is a full programming language while Javascript is used to make websites dynamic , so it works inside a webbrowser. You should figure what you want and make a choice.

Sign up to request clarification or add additional context in comments.

2 Comments

I was just trying to give a very brief overview. Obviously, "dynamic" is quite an understatement nowadays. The primary use of Javascript is still on the web 'though, while Java is used for offline, standalone applications more too.
Obviously there are other ways to interpret Javascript. I just stated the main application to give a beginning programmer some basic understanding. Feel free to correct me by going into all the details if you feel that adds something.
0

As others said, you need to figure out what you want.

Nevertheless, it is possible to run Javascript in java. Check javax.script package and check the docs: http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#evalfile

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.