TaffyDB, error says TAFFY is not a function

414 views Asked by At

I'm working on a web-based game with HTML, CSS & JavaScript, using Visual Studio. I'm using TaffyDB as a database. However, whenever I try to create a database using the function TAFFY, an error shows up on the console, saying that TAFFY isn't a function. I'm not sure where the mistake is, I believe I've linked the JS files to the HTML correctly, here are all the ways I've tried:

<script type="text/javascript" src="/taffy-min.js"></script>
<script type="text/javascript" src="./taffy-min.js"></script>
<script type="text/javascript" src="taffy-min.js"></script>
<script type="text/javascript" src="https://github.com/typicaljoe/taffydb/blob/master/taffy.js"

I have also tried including the full path, and for all of the above I tried it using 'taffy.js' instead of 'taffy-min.js'. I have also tried it with and without jQuery:

<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>

I am not sure if the mistake is the JS files not linking to the HTML properly, or if it's something entirely different. Code I used to set up a user:

var users = TAFFY([
        {
            "id": 1,
            "user": "John123",
            "level": 5,
            "gameType: "easy"
        }]);
1

There are 1 answers

3
lainatnavi On

First of all you have missing double quotes here: "gameType: "easy", should be "gameType": "easy". The error is saying that TAFFY is not a function: this means that there's another variable in the scope named TAFFY. In order to check if the taffy script is linked correctly open the console and type typeof this.TAFFY which should print "function". Hope this helps.