Javascript error CheckList is not a constructor

im getting an error: Uncaught TypeError: CheckList is not a constructor
and it says I have it in the main.js file…HELP!!! main.js file:

(function (window) {
	// body...

	var FORM_SELECTOR='[data-coffee-order="form"]';
	var CHECKLIST_SELECTOR='[data-coffee-order="checkList"]';
	//assigning namespaces to variables
	var App=window.App;
	var Truck=App.Truck;
	var Datastore=App.Datastore;
	var FormHandler=App.FormHandler;
	var CheckList=App.CheckList;

	var myTruck= new Truck( 'ncc-17',new Datastore());
	//to intercact with protected  instance of Truck write
	// code below and export it to global namespace

        truck.js:44 Truck # ncc-17 has pending orders: 

	// window.myCheckList=myCheckList;

	var myForm = new FormHandler(FORM_SELECTOR);
	// myForm.addSubmitHandler(myTruck.createOrder.bind(myTruck));
	// 	want createorder from truck.js to be called on but cannot pass a reference to
	// 	myForm.addSubmitHandler(); instead use bind reference above
	// 	 if we didnt do this the value of " this"  in createorder
	// 	  is changed and not be truck instance therfore we have errors

	// console.log(myForm);
	var myCheckList= new CheckList(CHECKLIST_SELECTOR);
		// createorder is the fn(data) and same below it


Hi @Naomi, try console.log(App) to see what properties are on it? I suspect App.CheckList is undefined, which means isn’t getting set (or might not be set early enough).

Also, when you see the exception, what line and file is it coming from? (screenshot would be :100: ) If I remember correctly, there’s another “module” that depends on the CheckList module, so if CheckList isn’t defined early enough, you’ll see this same error.

error coming from line:
var myCheckList= new CheckList(CHECKLIST_SELECTOR);

@Naomi Could you include a screenshot of running console.log(App) in the dev tools?

here is the snapshot

Thanks @Naomi, looks like CheckList is not being defined and added to App. Most likely that could mean:

  • Your <script> tag for CheckList has a typo, or isn’t in the right order in index.html. Would you post your index.html code here?
  • There’s a bug in checklist.js. Would you also attach that source code?

html file is attached. the script file is included in the file. cant send
the CheckList. js file , it was blocked by my computer for security reasons
so here it is :

(function(window) {

    // body...
    'use strict';
    var App=window.App || {};
    // importing APP and jQuery namespace line above and below
    var $=window.jQuery;
    function CheckList(selector){
            throw new Error('no selector provided');
            throw new Error('not find element with selector '+ selector);

    // the parameter, coffeorder is data passed that contains a
    //single coffe order like strength size etc...
    CheckList.prototype.addRow= function(coffeeOrder) {
        // pg 234
        var rowElement=new Row(coffeeOrder);
        //add the new row instance $row property to the checklist instance
        //this.$element with append() method

        // want mark up to appear after form submits, create another
        //accepts coffeOrder which is same data form createorder from
Truck.js file
        function Row(coffeeOrder){
            // use jquery to build DOM elements, more on pgs 229-231
            var $div=$('<div><div>',{
            var $label=$('<label><label>');
            var $checkbox=$('<input><input>',{
            var description=coffeeOrder.size + ' ';
                description+=coffeOrder.flavor+ ' ';
   ' , ';
            description+='(' + coffeeOrder.emailAddress + ')';
            description+= '[' + coffeeOrder.strength +' x ]';
            // below append() adds jquery collection or DOM elements
            // as child elements


    // exporting checklist to app namespace below


@Naomi ah, I don’t think you can attach files (other than images), so I don’t see index.html. Try copy-pasting your code into a post like you did for CheckList.js.


<!DOCTYPE html>
<meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="
<body class="container">
        <div class="panel panel-default">
            <div class="panel-body">
                <form data-coffee-order="form">
                            <!-- name attirbute is the key and what user
types in
                    will be the value -->
                    <div class="form-group">
                        <label for="coffeeOrder">Coffee Order</label>
                        <input id="coffeeOrder" class="form-control"
name="coffee" autofocus="">
                    <div class="form-group">
                        <label for="emailInput">email Address</label>
                        <input id="emailInput" class="form-control"
name="emailAddress" placeholder="">
                        <!-- mark up for radio buttons -->
                    <div class="radio">
                            <input type="radio" name="size" value="short">

                    <div class="radio">
                            <input type="radio" name="size"  value= "Tall"

                    <div class="radio">
                            <input type="radio" name="size" value="grande">

                    <div class="form-group">
                        <label for="flavorShot">Flavor Shot</label>
                        <select id="flavorShot" class="form-control"
                            <option value="">None</option>
                            <option value="caramel">Caramel</option>
                            <option value="almond">Almond</option>
                            <option value="mocha">Mocha</option>
                    <div class="form-group">
                        <label for="strengthLevel"> Caffeine Rating</label>
                            <!-- defualt value of 30. -->
                        <input id="strengthLevel" name="strength"
value="30" type="range">

            <button type="submit" class="btn btn-success">Sumbit</button>
            <button type="submit" class="btn btn-default">Reset</button>

        <div class=" panel panel default">
            <div class="panel-body">
                <h4>Pending Orders : </h4>
                <div data-coffee-order="checkbox" ></div>

 <script src=""
 <script type="text/javascript" src="scripts/CheckList.js"
<script type="text/javascript" src="scripts/datastore.js"
<script type="text/javascript" src="scripts/truck.js"

<script type="text/javascript" src="scripts/formhandler.js"
<script type="text/javascript" src="scripts/main.js"


I appreciate your efforts to help.

Hi @Naomi, could you attach a screenshot of your Chrome console when you open the page? I see a couple syntax errors in checklist.js due to line breaks in comments, but it’s hard to tell if that was just something that happened when you copy-pasted. Thanks!

here it is

@Naomi hmm, try putting a console.log statement at the bottom of checklist.js, right after the App.CheckList=CheckList; line — I want to confirm if it’s being executed.

If it is, the bug may be in datastore.js (maybe it’s clobbering window.App)

oh it did work in console! Apparently in my main.js file I wrote,
var checkList=App.CheckList;
instead of
var CheckList=App.CheckList;

wow. thanks! Your assistance made me pay close attention to my code!

are you on linkedin?

@Naomi Hurray, onward!

Yep — I am @nybblr pretty much everywhere, including LinkedIn :slight_smile: