Skip to content

Instantly share code, notes, and snippets.

@airportyh
Created August 17, 2016 22:37
Show Gist options
  • Select an option

  • Save airportyh/cddbe4c414f690433259b5714d6b3a6e to your computer and use it in GitHub Desktop.

Select an option

Save airportyh/cddbe4c414f690433259b5714d6b3a6e to your computer and use it in GitHub Desktop.

Exercises 2

1 to 10

Using a while loop. Print the numbers from 1 to 100, one on a line.

1 to 100

Using a while loop. Print the numbers from 1 to 100, one on a line.

Odd Numbers

Print the odd numbers between 1 and 100 inclusive.

String Parts

Given this string below, split the string by the comma so that you have an array of 5 strings total, each being a letter.

var str = "A,B,C,D,E";
// fill in logic

Print the numbers

Given an array of numbers, print each number. Change the values around to make sure it still works.

var numbers = [2, 4, 5, 6, 8];
// fill in logic

Print Odd Numbers

Given an array of numbers, print each number in it that is odd. Change the values around to make sure it still works.

var numbers = [2, 4, 5, 6, 8];
// fill in logic

Sum the numbers

Given an array of numbers, sum them, and then print out the sum. Change the values around to make sure it still works.

var numbers = [2, 4, 5, 6, 8];
// fill in logic

Calling a function

Given this function, call it to make it print "Hello world!".

function hello() {
  console.log('Hello world!');
}
// fill in code

Calling a function 2

Given this function, call it to make it print "Hello, Bob!".

function helloTo(name) {
  console.log('Hello, ' + name + '!');
}
// fill in code

Calling a function 3

Given this function, call it to make it return the result of 6 divided by 2. Store the result in a new variable called result.

function divide(a, b) {
  return a / b;
}

Writing a function

Write a function times2 that takes a number parameter num, and returns the result of multipling the number by 2. After you write the function, call the function like times2(5), and store the result in a new variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment