Mixed Messages - Capital cities and heads of state

Hi! :slight_smile:

I just finished my Mixed Messages portfolio project and would love to have some feedback if anyone has any to offer.


Hey, @beta5952191560.

Iโ€™ve looked at your code, and have a suggestion. Consider whether your switch...case logic is necessary. Your random function is returning a number. Think about how you could utilize that number with your already defined arrays.

Edit: The design of the page is great! :slight_smile:

1 Like


Thanks for taking time to look over it. :slight_smile: Iโ€™m sorry my response has been slow.

I get it in theory, displaying the index value of the number being returned? I think? But I canโ€™t think quite how to write it. :sweat_smile:

1 Like

Not sure I would use an object to store the arrays, but if I did, I would take advantage of the ability for an object to also have its own methods:

//The following are arrays in which the different random values will come from
const arrays = {
    'countries' : ['England', 'Italy', 'France', 'Germany', 'Russia', 'Spain', 'The Netherlands', 'Switzerland', 'Hungary'],
    'capitals' : ['London', 'Rome', 'Paris', 'Berlin', 'Moscow', 'Madrid', 'Amsterdam', 'Zurich', 'Budapest'],
    'leaders' : ['Boris Johnson', 'Sergio Mattarella', 'Emmanuel Macron', 'Frank-Walter Steinmeier', 'Vladimir Putin', 'Pedro Sanchez', 'Mark Rutte', 'Guy Parmelin', 'Janos Ader'],

    return this[arr][Math.floor(Math.random() * arr.length)];

function randomMsg() { 
    return `${arrays.randomSelection('capitals')} is the capital city of ${arrays.randomSelection('countries')}. The head of state there is ${arrays.randomSelection('leaders')}!`