Unit 7 - Publishing Libraries

In unit 7, when students are building their functions to publish libraries, they are encouraged to test those functions using the console log. Many of my students did this, and then because the code that accomplished the testing was outside of the actual functions, when didn’t bother to remove that before publishing their libraries (thinking it might be helpful for their classmates to see how they ran their tests). Their thinking was: when other students call my function from the library, it is only going to call the code within the function itself, and extraneous information will be ignored. The outcome was not what they expected: when other students imported their libraries and ran their own tests, their console logs showed not only what they logged themselves, but all of the console logs that were written by the library’s author.

Student A’s Invalid Library Code:

// establishing global variables for the purpose of testing the functions
var testGlobalListAnimals = [“frog”, “bird”, “dog”, “cat”];
var testGlobalListNumbers = [5872,870,87,28,42];
var testGlobalListLyrics = [“Baa Baa Black Sheep, have you any wool”, “yes sir yes sir three bags full”, “twinkle twinkle little star”, “how i wonder what you are”];
var testGlobalListLists = [testGlobalListAnimals, testGlobalListNumbers, testGlobalListLyrics];

// testing numberedList three times with four different lists, one with strings, one with numbers, one with strings that are made of multiple words, and one made out of other lists.
console.log(“Testing numberedList 1: list = animals \n” + numberedList(testGlobalListAnimals));
console.log(“\n” + “\n”);
console.log(“Testing numberedList 2: list = numbers \n” + numberedList(testGlobalListNumbers));
console.log(“\n” + “\n”);
console.log(“Testing numberedList 3: list = lyrics \n” + numberedList(testGlobalListLyrics));
console.log(“\n” + “\n”);
console.log(“Testing numberedList 4: list = other lists \n” + numberedList(testGlobalListLists));
console.log(“\n” + “\n”);

// testing combineList
console.log(“Testing combineList 1: \n” + combineList(testGlobalListAnimals, testGlobalListNumbers));
console.log(“\n” + “\n”);
console.log(“Testing combineList 2: \n” + combineList(testGlobalListNumbers, testGlobalListLyrics));
console.log(“\n” + “\n”);
console.log(“Testing combineList 3: \n” + combineList(testGlobalListLyrics, testGlobalListAnimals));
console.log(“\n” + “\n”);

// numberedList - Takes a list that has been pre-established as a global variable in your programand puts each element numbered on its own line.
// list {list} - A list of elements.
// return {string} - A text string of each element of the list numbered on its own line.
function numberedList(list) {
var filteredList = ;
for (var i = 0; i < list.length; i++) {
appendItem(filteredList, i+1 + “. " + list[i]);
}
return(filteredList.join(”\n"));
}

// combineList - A function which filters two lists into one, longer, list.
// list {list} - A list of elements.
// return {list} - The new list consisting of both the arguments one after the other.
function combineList(list1, list2) {
var newList = ;
for (var i = 0; i < list1.length; i++) {
appendItem(newList, list1[i]);
}
for (var a = 0; a < list2.length; a++) {
appendItem(newList, list2[a]);
}
return(newList);
}

Student B’s test code:

var dogBreeds = ["chow-chow", "lab", "shepherd", "xolo"];
console.log(U7LibrariesProjectPart1.numberedList(dogBreeds));

Student B’s Console Log Results:

* "Testing numberedList 1: list = animals 1. frog 2. bird 3. dog 4. cat"

* " "

* "Testing numberedList 2: list = numbers 1. 5872 2. 870 3. 87 4. 28 5. 42"

* " "

* "Testing numberedList 3: list = lyrics 1. Baa Baa Black Sheep, have you any wool 2. yes sir yes sir three bags full 3. twinkle twinkle little star 4. how i wonder what you are"

* " "

* "Testing numberedList 4: list = other lists 1. frog,bird,dog,cat 2. 5872,870,87,28,42 3. Baa Baa Black Sheep, have you any wool,yes sir yes sir three bags full,twinkle twinkle little star,how i wonder what you are"

* " "

* "Testing combineList 1: frog,bird,dog,cat,5872,870,87,28,42"

* " "

* "Testing combineList 2: 5872,870,87,28,42,Baa Baa Black Sheep, have you any wool,yes sir yes sir three bags full,twinkle twinkle little star,how i wonder what you are"

* " "

* "Testing combineList 3: Baa Baa Black Sheep, have you any wool,yes sir yes sir three bags full,twinkle twinkle little star,how i wonder what you are,frog,bird,dog,cat"

* " "

Our conclusion was that libraries should include ONLY functions and comments and no other code at all. That made sense on some level: the purpose of a library is to simplify, so storing ONLY what is necessary there is cleaner and more efficient. But it also caused confusion, because until now, we have understood that when calling a function, we are ONLY calling on the code within that function.

I looked back through all the previous documentation including lesson plans, the presentation, and student instructions in code studio, and I never saw anything that EXPLICITLY addressed this. I would think that it should be included in the lesson plan for Unit 7: Lesson 9.

Please let me know if I have misunderstood what happened, or if our conclusion is wrong. Many thanks!

1 Like

Hi @dawnstiller, thanks for sharing about this! You haven’t misunderstood anything. In fact, you’ve helped reveal something that needed to be clarified! The quickest solution to this issue that will prevent students from having to recreate the tests is to have them comment out the test calls to the library functions. These comments will still be imported when sharing with others but they will no longer affect the functionality and can be preserved if they need to be tweaked later to test updates.

I’ve added a note to the project guide and a slide to the slide deck to highlight this workaround. I will make an update to the lesson plan as well. Thanks again and please let me know if this helps address the issue!

3 Likes