Interpreter Bug: Functions executing without being called


#1



https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/0/4?curriculum_id=506324b3a7dffd00020bf661

Functions are printing to the console both when they are defined as well as when they are called. Functions should only execute and print to the console when they are called, not when they are defined. This issue does not occur with another interpreter like runnable.com


var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Jones",
        number: "(516) 555-0000",
        address: ['1 Fun Lane','Springfield','MA','01101']
    },
    steve: {
        firstName: "Jane",
        lastName: "Doel",
        number: "(343) 300-0000",
        address: ['2 Ocean View Ave','Makeupville','ME','02000']
    }
};

var search = function(name) {
    console.log("name = " + name); // This prints twice for each key
    for(var key in friends) {
        if(friends[key].firstName === name) {
            console.log("Hit found");
            console.log("Name = " + friends[key].firstName + " " + friends[key].lastName);
            console.log("Number = " + friends[key].number);
            console.log("Address = ");
            for(i = 0; i < friends[key].address.length; i++) {
                console.log(friends[key].address[i]);
            }
            return friends[key];
        }
    }
}

search(prompt("What name to search for?"));

The output is spitting out a lot of excess that is not expected and does not happen with other interpreters:

name = Jane
Hit found
Name = Jane Doel
Number = (343) 300-0000
Address = 
2 Ocean View Ave
Makeupville
ME
02000
name = Steve
name = Steve
name = Bill
Hit found
Name = Bill Jones
Number = (516) 555-0000
Address = 
1 Fun Lane
Springfield
MA
01101
{"firstName":"Jane","lastName":"Doel","number":"(343) 300-0000","address":["2 Ocean View Ave","Makeupville","ME","02000"]}


#2

I also don't see why name is being reassigned. I should note that I passed in "Jane" when prompted in this example.


#3

There are two things that are possibly making this happen; one, it is a bug; or two, Codecademy is purposefully doing it so that you can see the output of your code without having to call a bunch of functions. Honestly though, I do agree with you that it is probably a bug.

I don't know why it is allowing you to reassign steve's name to Jane though. Also possibly a bug.


#4

I'm now 100% confident there is a bug here in which the console is printing out names that have been completely removed from my code.


#5

Did you reload the page as well?


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.