Skip to content

JavaScript Pretest 2

Asabeneh edited this page Nov 12, 2019 · 6 revisions
  1. Declare firstName, lastName, age variables and assign your first name, your last name and your age to the variables.

  2. Concatenate the firstName , a space and lastName variable and assigned to a fullName variable.

  3. Check if your name is long or short. If the length of your first name is greater than 7, you have a long name else you have a short name

  4. Declare an array called shoppingBasket and put at least 5 items you commonly put to your shopping basket.

  5. Declare a function called sumOfAllNumbers, it takes a positive integer as a parameter and it returns the sum of all the numbers

  6. Declare a function called listShoppingItems, it takes your shopping basket array you declared at question 4 as a parameter and it prints out the capitalized shopping items.

        const list = [
        'Banana',
        'Tomato',
        'Milk',
        'Egg',
        ]
        listShoppingItems(list)
        BANANA
        TOMATO
        MILK
        EGG
  7. Declare a function called getPersonInfo, it takes firstName, lastName, age and country as parameter and it returns information about you. eg.

    getPersonInfo('Asabeneh', 'Yetayeh', 200, 'Finland')
    I am Asabeneh Yetayeh. I am 200 years old. I am from Finland.
  8. Declare a function called randomNumbers which can return an array of 7 numbers which range 1-20.

    randomNumbers()
    [9,4, 3, 5, 2, 8, 2]
  9. Declare a function called sumOfEven, it takes a positive integer as a parameter and it returns the sum of all numbers

    sumOfEven(10)
  10. Declare an object called person, it has firstName, lastName, age, country, getPersonInfo keys. The getPersonInfo is a method which return about the person object. eg.

    I am Asabeneh Yetayeh. I am 200 years old. I live in from Finland.