Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Last active March 17, 2023 15:03
Show Gist options
  • Select an option

  • Save sandrabosk/ba3e880e5f18877dec7a44c7c75d8680 to your computer and use it in GitHub Desktop.

Select an option

Save sandrabosk/ba3e880e5f18877dec7a44c7c75d8680 to your computer and use it in GitHub Desktop.
// https://gist.github.com/sandrabosk/d26d441d8e9a5912c6084b0f9e5c2c5d
// Goal: display the symbol "!" from every variable
const variable1 = [4, 'a', true, '!', 3.14];
console.log(1, variable1[3]);
console.log(1, variable1.toString()[9]);
const variable2 = {
a: '?',
b: '!',
c: '€',
d: '%',
};
console.log(2, variable2.b);
// console.log(2, variable2['b']);
const variable3 = 'Hello Ironhack!';
console.log(3, variable3[variable3.length-1]);
// console.log(3, variable3[14]);
// console.log(3, variable3.charAt(14));
console.log(3, variable3.substr(-1));
const variable4 = ['Hello', 'Hola', 'Salut!', 'Hallo'];
console.log(4, variable4[2][5]);
console.log(4, variable4[2].substr(-1));
const variable5 = {};
variable5[variable4[0]] = '!';
const test5 = variable5[variable4[0]]
console.log(5, test5)
console.log(5, variable5['Hello']);
console.log(5, variable5.Hello);
// No need to remember this example
var variable6 = {
3: '!',
};
console.log(6, variable6[3]);
// console.log(6, variable6['3']);
const variable7 = [[[[[['!']]]]]];
console.log(7, variable7[0][0][0][0][0][0]);
console.log(7, variable7.toString());
const variable8 = {
a: {
b: {
c: { d: { e: 'I am not here' } },
},
f: {
g: 'I am not here also',
h: {
i: '!',
},
},
},
};
console.log(8, variable8.a.f.h.i);
// console.log(8, variable8['a']['f']['h']['i']);
const variable9 = {
europe: {
spain: ['Madrid', 'Barcelona'],
france: ['Paris'],
germany: ['Berlin!'],
},
america: {
'united-states': ['Miami'],
mexico: ['Mexico City'],
},
};
console.log(9, variable9.europe.germany[0][6]);
console.log(9, variable9.europe.germany[0].substr(-1));
const variable10 = {
europe: {
spain: ['Madrid', 'Barcelona'],
france: ['Paris'],
germany: ['Berlin'],
},
america: {
'united-states': ['Miami!'],
mexico: ['Mexico City'],
},
};
console.log(10, variable10.america['united-states'][0][5]);
console.log(10, variable10.america['united-states'][0].substr(-1));
const str10 = variable10.america['united-states'][0]
console.log(10, str10[str10.length-1]);
// Uncomment the following lines
// console.log(variable1...); // => "!"
// console.log(variable2...); // => "!"
// console.log(variable3...); // => "!"
// console.log(variable4...); // => "!"
// console.log(variable5...); // => "!"
// console.log(variable6...); // => "!"
// console.log(variable7...); // => "!"
// console.log(variable8...); // => "!"
// console.log(variable9...); // => "!"
// console.log(variable10...); // => "!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment