Intro to Java Script
Macys.com class
by iboulder
HTML
<h1>Primitives Exercise</h1>
JavaScript
/******************************************************************************/
/* EXERCISE 1: Example exercise. The function below is an example
exercise to demonstrate how the rest of the exercises
work.
Calculate the sum of 1 and 2 then return the answer.
Updated to 3 and 7 to see how it works
*/
function Exercise1() {
return 3 + 7;
}
console.group('Exercise 1');
console.assert(Exercise1() == 10); // test output
console.log('hello world'); //slm test, see in console area
console.groupEnd('Exercise 1');
/******************************************************************************/
// EXERCISE 2: Create (and return) a string with at least 5 characters
function Exercise2() {
var myname = 'sheryl';
//return var myname = "sheryl"
return myname
// Your code here.
}
console.group('Exercise 2');
console.assert(Exercise2().length >= 5);
console.log("string defined is " + Exercise2());
console.groupEnd('Exercise 2');
/******************************************************************************/
// EXERCISE 3: Create (and return) an array that has at least 5 elements
function Exercise3() {
// Your code here.
var myArray = ['frankie', 'flo', 'skippy','suka', 'bubba'];
//var myArray = [99,98,97,96,95];
return myArray;
}
console.group('Exercise 3');
console.assert(Exercise3().length >= 5);
console.log("array defined is " + Exercise3());
console.groupEnd('Exercise 3');