skip to Main Content

I learned math.random and math.floor through websites but still stuck in the middle of my code. I’m newbie js is my first language.

//Create a business name generator by combining list of Adjective and Shop name and Another Word 

let a = math.floor(math.random() * 3);
let b = math.floor(math.random() * 3);
let c = math.floor(math.random() * 3);

let Adjectives = {
    0: Crazy,
    1: Amazing,
    2: Fire,
}

let ShopName = {
    0: Engine,
    1: Foods,
    2: Garments,
}

let AnotherWords = {
    0: Bros,
    1: Limited,
    2: Hub,
}

console.log(`${Adjectives[a]} ${ShopName[b]} ${AnotherWords[c]}`);

Expected answer = Crazy Engine Limited/ Amazing Garments Bros (Any 3 words combining and making a name)

3

Answers


  1. It’s a type-o

    math should be Math 🙂

    edit: Also, your Adjectives, ShopName and OtherWords should be arrays and not object.

    example:

    //Create a business name generator by combining list of Adjective and Shop name and Another Word 
    
    const a = Math.floor(Math.random() * 3);
    const b = Math.floor(Math.random() * 3);
    const c = Math.floor(Math.random() * 3);
    
    const adjectives = ['Crazy', 'Amazing', 'Fire'];
    
    const shopName = ['Engine', 'Foods', 'Garments'];
    
    const anotherWords = ['Bros', 'Limited', 'Hub'];
    
    console.log(`${adjectives[a]} ${shopName[b]} ${anotherWords[c]}`);
    
    Login or Signup to reply.
    1. Math is written with a capital letter
    2. Your words are not variables so you must write it in ""
    //Create a business name generator by combining list of Adjective and Shop name and Another Word 
    
    let a = Math.floor(Math.random() * 3);
    let b = Math.floor(Math.random() * 3);
    let c = Math.floor(Math.random() * 3);
    
    let Adjectives = {
        0: "Crazy",
        1: "Amazing",
        2: "Fire",
    }
    
    let ShopName = {
        0: "Engine",
        1: "Foods",
        2: "Garments",
    }
    
    let AnotherWords = {
        0: "Bros",
        1: "Limited",
        2: "Hub",
    }
    
    console.log(`${Adjectives[a]} ${ShopName[b]} ${AnotherWords[c]}`);
    Login or Signup to reply.
  2. You can either use the default Math library or import a library such as maths to get your expected outcome. Here, I suppose you are trying to use the default math library (i.e. Math).

    Also please make sure that your string values must be within quotes (").

    let a = Math.floor(Math.random() * 3);
    let b = Math.floor(Math.random() * 3);
    let c = Math.floor(Math.random() * 3);
    
    let Adjectives = {
        0: "Crazy",
        1: "Amazing",
        2: "Fire",
    }
    
    let ShopName = {
        0: "Engine",
        1: "Foods",
        2: "Garments",
    }
    
    let AnotherWords = {
        0: "Bros",
        1: "Limited",
        2: "Hub",
    }
    
    console.log(`${Adjectives[a]} ${ShopName[b]} ${AnotherWords[c]}`);
    

    Alternatively, you can use a list instead of a numbered directory.

    let Adjectives = ["Crazy", "Amazing", "Fire"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search