0
var fs = require('fs');

var data = fs.readFileSync('colors.txt','utf8')
console.log (data);

const colors = {
  green: {
    wrapperBackground: "#E6E1C3",
    headerBackground: "#C1C72C",
    headerColor: "black",
    photoBorderColor: "#black"
  },
  blue: {
    wrapperBackground: "#5F64D3",
    headerBackground: "#26175A",
    headerColor: "white",
    photoBorderColor: "#73448C"
  },
  pink: {
    wrapperBackground: "#879CDF",
    headerBackground: "#FF8374",
    headerColor: "white",
    photoBorderColor: "#FEE24C"
  },
  red: {
    wrapperBackground: "#DE9967",
    headerBackground: "#870603",
    headerColor: "white",
    photoBorderColor: "white"
  }
};
console.log(colors.data);

When I log colors.data. data is equal to a string of "blue". So it should log as colors.blue. It logs as undefined. How can I get data which is read from a different file, to act as the color property it is given? The colors.txt holds a single line of string which is, blue.

1 Answers1

0

The colors object doesn't have a data property.

Try console.log(colors[data]);

Tomaso Albinoni
  • 1,003
  • 1
  • 8
  • 19