# Create a Hash Table doesn't pass any tests \[beta\]

**URL:** <https://forum.freecodecamp.org/t/create-a-hash-table-doesnt-pass-any-tests-beta/138057>\
**Category:** General\
**Created:** [July 24, 2017, 9:39pm UTC](https://forum.freecodecamp.org/t/create-a-hash-table-doesnt-pass-any-tests-beta/138057 "2017-07-24T21:39:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enikol](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/enikol/32/21175_2.png) [@Enikol](https://forum.freecodecamp.org/u/Enikol)\
**Post date:** [July 24, 2017, 9:39pm UTC](https://forum.freecodecamp.org/t/create-a-hash-table-doesnt-pass-any-tests-beta/138057/1 "2017-07-24T21:39:28Z")

</div>

Hi! I can’t complete the ‘Create a Hash Table’ challenge from beta curriculum. It doesn’t pass any test, including the frist one, which is very strange and I can’t find the problem. Here’s my code:

```
var called = 0; 
var hash = function(string) {
called++;
var hash = 0;
for (var i = 0; i < string.length; i++) { hash += string.charCodeAt(i); }
return hash;
};
var HashTable = function() {
this.collection = {};
// change code below this line
this.add = function(key, value) {
 var hashKey = hash(key);
if (this.collection.hasOwnProperty(hashKey)){
  this.collection[hashKey].push({[key]: value});
} else {
this.collection[hashKey] = [];
  this.collection[hashKey].push({[key]: value});
}
//console.log(this.collection);
 };
 this.lookup = function(key) { 
	var hashed = hash(key);
	if (this.collection.hasOwnProperty(hashed)) {
		var bucket = this.collection[hashed];
		var find = function(index) {
			if (bucket[index].hasOwnProperty(key)) {
				return bucket[index][key];
			} else if (index != 0) {
				return find(index - 1);
			} else {
				return null;
			};
		};
		return find(bucket.length - 1);
	} else {
		return null;
	};
};
 this.remove = function(key){
 var hashed = hash(key);
 if (this.collection.hasOwnProperty(hashed)){
if (this.collection[hashed].length === 1){
delete this.collection[hashed];
} else {
 this.collection[hashed] = this.collection[hashed].filter(function(item){
 return !item.hasOwnProperty(key);
 });
 }
} else {return null;}
};
// change code above this line
 };
```

---

<div class="post-metadata">

**Author:** ![marigerr](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/marigerr/32/61636_2.png) [@marigerr](https://forum.freecodecamp.org/u/marigerr)\
**Post date:** [July 25, 2017, 12:44am UTC](https://forum.freecodecamp.org/t/create-a-hash-table-doesnt-pass-any-tests-beta/138057/2 "2017-07-25T00:44:31Z")

</div>

Hi! Your code passed all tests when I tried it. (nice job btw)  
Maybe try refreshing page and running tests again?

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:47pm UTC](https://forum.freecodecamp.org/t/create-a-hash-table-doesnt-pass-any-tests-beta/138057/3 "2021-01-17T20:47:25Z")

</div>


