Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function renderInventory(arr) { 
  var result = [];
  
  for(var i = 0; i < arr.length; i++){
    for(var j = 0; j < arr[i].shoes.length; j++){
       result.push(arr[i].name + ', ' + arr[i].shoes[j].name + ', ' + arr[i].shoes[j].price);
    }
  }
  
  return result.join('\n');
}
// try pushing your rendered strings to an array
// then join the array using the new line operator instead
// because right now, the way you’re returning it doesn’t do that
var currentInventory = [{
    name: 'Brunello Cucinelli',
    shoes: [{
        name: 'tasselled black low-top lace-up',
        price: 1000
    }, {
        name: 'tasselled green low-top lace-up',
        price: 1100
    }, {
        name: 'plain beige suede moccasin',
        price: 950
    }, {
        name: 'plain olive suede moccasin',
        price: 1050
    }]
}, {
    name: 'Gucci',
    shoes: [{
        name: 'red leather laced sneakers',
        price: 800
    }, {
        name: 'black leather laced sneakers',
        price: 900
    }]
}];
var expected = ["Brunello Cucinelli, tasselled black low-top lace-up, 1000", "Brunello Cucinelli, tasselled green low-top lace-up, 1100", "Brunello Cucinelli, plain beige suede moccasin, 950", "Brunello Cucinelli, plain olive suede moccasin, 1050", "Gucci, red leather laced sneakers, 800", "Gucci, black leather laced sneakers, 900"];
var actual = renderInventory(currentInventory);
console.log(actual);
function assertrenderInventory(actual, expected, testName){
  if(JSON.stringify(actual) === JSON.stringify(expected)){
    console.log('passed');
  }else{
    console.log('FAILED [' + testName + '] Expected "' + actual + '" to be "' + expected + '"');
  }
}
assertrenderInventory(actual, actual, 'testing renderInventory');
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers