1

Am trying to call a JS script from a function library in another script.

Eg. iceCreams.Js contains --->

iceCream(iceCreams){
var profit = .54

var Total = iceCreams * profits

return Total;

}

register.js contains -->

dailyTotals(wages, iceCreams){

var total = iceCream(iceCreams);

var profit = iceCreaps - wages

return wages;
}

Any help pointing me in the right direction?!

8
  • 1
    You are missing the function keywords btw. Commented Jun 3, 2011 at 9:01
  • ...and iceCreaps should probably be iceCreams. (Also recommend not relying on semicolon insertion; always include the semicolons required.) Commented Jun 3, 2011 at 9:03
  • Omitting semi-colons is bad practise. Using them willy-nilly is even worse. Always use semi-colons. It'll come back to haunt you when you start programming in a language which requires them. Commented Jun 3, 2011 at 9:04
  • So I dont have to point to it iceCream : iceCream(iceCreams)? Commented Jun 3, 2011 at 9:07
  • Please explain your last comment, I don't understand what you are trying to say... Commented Jun 3, 2011 at 9:16

3 Answers 3

3

Make sure your page loads the iceCream.Js before the register.js:

<html>
...
<script type="text/javascript" src="iceCream.Js"></script>
<!-- now you can use functions in iceCream.Js in your register.js -->
<script type="text/javascript" src="register.js"></script>
....
</html>
Sign up to request clarification or add additional context in comments.

Comments

1

Running the javascripts is done in client side and after rendering the full html. So, you have to add script tag for the library javascripts before consuming ones. Just add script tag for the library before the one for register:

<script type="text/javascript" src="iceCreams.Js"></script>
<script type="text/javascript" src="register.js"></script>

Comments

0

Both script files must be referenced on the page they are used.

Additionally, to get IntelliSense in Visual Studio to work within the script, add the following line to the top of register.js:

/// <reference path="iceCreams.js" />

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.