Question

Instructions Read the questions and instructions carefully as typos or misspellings may cause errors. Variables and...

Instructions

  • Read the questions and instructions carefully as typos or misspellings may cause errors.

  • Variables and functions are persistent throughout the challenge. If a question asks you to use an object from a previous question, please do so :)

  • Hit Run at the top of the page to test your code and execute any functions you've called.

  • When you're finished, just hit Submit. Our team will review submissions in the order that they're received, and will submit feedback through this app or through email.

  • You may use W3Schools.com, Codecademy, or Google as resources. That said, any cheating or copying of other applicants' code will disqualify your application!

  • Please note: Each applicant may submit 3 attempts, and all are considered. We will grade submissions only after your initial application is reviewed and approved. You will still need to pass the interview stage for admission.

Questions

  1. Declare two variables, a string and an integer named fullName and birthYear, and set them equal to your name (just first and last, don't include middle names or suffixes) and your birth year.

  2. Declare an empty array called myArray.

  3. Add the variables from #1 (fullName and birthYear) to myArray using the push method. Print myArray to the console.

  4. Declare a variable named splitName, and set it equal to fullName split into two separate objects in an array using the split method. In other words, splitName should equal ["FirstName", "LastName"] when printed to the console. Print splitName to the console.

  5. Write a simple function that takes no parameters called sayHello. When called, this function should print "Hello, ____!" to the console, where the blank is equal to the first index value in the splitName array from the previous question. Call the function.

  6. Write another function called calcAge. This function should take one parameter, and it should return your implied age (don't worry about months). Call the function passing the current year as the parameter.

  7. Starting with the basic function given below, write a function called sumOddNumbers that will print to the console and return the sum of all the odd numbers from 1 to 5000. Consider using a loop, and don't forget to call the function afterwards!

function sumOddNumbers() {

var sum = 0;

// Your code here

console.log(sum);

return sum;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

defining full name and birth year variables

var fullName="Oliver Queen";

var birthYear=1994;

creating an empty array

var myArray=[];

pushing full name and birth year to the array

myArray.push(fullName);

myArray.push(birthYear);

printing array to the console

console.log(myArray);

splitting name by white space to get an array of strings

var splitName=fullName.split(" ");

printing array

console.log(splitName);

function to print hello <firstname>

function sayHello(){

printing hello with element at index 0 of splitname

console.log("Hello, "+splitName[0]+"!");

}

calling above function

sayHello();

function to calculate and return the age from current year

function calcAge(currentYear){

return currentYear-birthYear;

}

printing age, when current year is 2019

console.log(calcAge(2019));

function to find the sum of odd numbers between 1 to 5000

function sumOddNumbers()

{

var sum = 0;

looping from 1 to 4999, incrementing by 2 each time

for(var i=1;i<5000;i+=2){

adding i to sum

sum+=i;

}

printing and returning sum

console.log(sum);

return sum;

}

calling above function

sumOddNumbers();

/OUTPUT/

["Oliver Queen", 1994]

["Oliver", "Queen"]

"Hello, Oliver!"

25

6250000

Add a comment
Know the answer?
Add Answer to:
Instructions Read the questions and instructions carefully as typos or misspellings may cause errors. Variables and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solutions. 1. write the code using function 2. Please try to implement a function after the main function and provide prototype before main function. Total Characters in String Array 10 points Problem 2 Declare a string array of size 5. Prompt the user enter five strings that are...

  • Using Swift playground and / or the command line for macOS (open Xcode, create a new...

    Using Swift playground and / or the command line for macOS (open Xcode, create a new Xcode project, macOS, command line tool), practice the following exercises: Exercise: Swift Variables Declare 2 variables/constants with some random values and any name of your choice Considering these 2 variables, one as a value of PI and other as a radius of circle, find the area of circle Print the area of circle Declare a string variable explicitly with value “Northeastern”. Declare a string...

  • In C Write a couple of functions to process arrays. Note that from the description of...

    In C Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an int array and size, and...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solu...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solutions. Instructions 1. Read instructions carefully! 2. Use C++ syntax only, C syntax will not be accepted. 3. Always use braces to define blocks. 4. Indent all lines within a block. Each block requires one more tab. 5. Organize your code well with proper formatting and a single...

  • Make a public class called ManyExamples and in the class... Write a function named isEven which...

    Make a public class called ManyExamples and in the class... Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd. Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the...

  • l ask Write a C++ program that accomplishes the following tasks 1. Write a function that...

    l ask Write a C++ program that accomplishes the following tasks 1. Write a function that finds the average of current element and the next element in given array named as "elements" and stores the new found averages into another array called "averageArray". Note: For the last element you can just divide the value of last element by 2 Write a function that takes both the given array and average array you just created along with a variable "productofArrays" using...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

  • Program Overview This brief exercise is designed for you to consider how reference variables behave when...

    Program Overview This brief exercise is designed for you to consider how reference variables behave when you are passing them as arguments by-value. Instructions Name your class References.java. 1. Implement the following methods. 1.1 Method name: readStudentNames Purpose: This method accepts an array of strings as a parameter. It loops through the array and asks the user to input names. It populates the array of strings with the names. Parameters: an array of Strings, stringArray Return type: void In the...

  • Create a #define called MAPSIZE. Set to 10. Create global variables DirectionsFilename and MapFilename. Use char...

    Create a #define called MAPSIZE. Set to 10. Create global variables DirectionsFilename and MapFilename. Use char arrays and set them to nulls by using {}. Create a structure called RowCol that has two int members called row and col to hold the row and column. Function MoveNorth should have a return value of void and a parameter of a pointer to RowCol. { To move north, you need to subtract 1 from PositionPtr->row. Before doing so, you need to check...

  • in java no mathcall please ennas are out of date.Please sign was wkollieemail.cpeedu so we can...

    in java no mathcall please ennas are out of date.Please sign was wkollieemail.cpeedu so we can verily your subscription Sign In ASSIGNMENT Unit 9 Methods, Arrays, and the Java Standard Class Library Reimplementing the Arrays class (60 points) The Arrays class, which is also part of the Java standard class library, provides various class methods that perform common tasks on arrays, such as searching and sorting. Write a public class called MyArrays, which provides some of the functionality which is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT