Joseph Cisar Student Portfolio

About Me Fields Report JavaScript Exercises and Projects Contact Usability and Accessibility

Exercise 1

Problem Statement

Write a program that calculates the total price of a pair of Nike shoes.

Plan

Ask user for price of shoes

Solution

var shoePrice = parseInt(document.getElementById('shoePriceInput1').value);
var totalCost = shoePrice + (shoePrice * .0625);
document.getElementById("cost1").innerHTML = "Total Cost = " + totalCost;

Demonstration

A normal pair of Nike shoes costs around $70 with a 6.25% sales tax. Enter different integers to see how other shoe prices vary.


Exercise 2

Problem Statement

Write a program that compares ages to see if a child should leave the county or not.

Plan

Ask user for an age

Solution

var age, voteable;
age = document.getElementById("age").value;
voteable = (age < 5) ? "Too young":"Old enough";
document.getElementById("travelAge").innerHTML = voteable + " to leave the country.";

Demonstration

*Based off of surveys* People believe children shouldn't travel out of the country until a certain age. What age do you think? Enter the age and see if it's too young or old enough.

Exercise 3

Problem Statement

Write a program that says "Hello World!" using JavaScript.

Plan

Greet the user with "Hello World!"

Solution

document.getElementById("demo").innerHTML = "Hello World!";

Demonstration

Exercise 4

Problem Statement

Write a program for when a user enters the page, the user is asked to enter one's name and be greeted to the page.

Plan

Ask for user name with Input and show Output

Solution

var name = prompt('What is your name?');
alert ('Welcome' + ', to my JavaScript exercises, ' + name + '!');
alert(name);
document.write(name);
document.getElementById("demo").innerHTML = carName;

Demonstration

Exercise 5

Problem Statement

Write a program that loops all forward rugby positions in order.

Plan

Show all forward rugby positions looped in order.

Solution

var positions = ["Loosehead Prop", "Hooker", "Tighthead Prop", "Lock", "Lock", "Flanker", "Flanker", "Number 8"];
var i = 0;
var len = positions.length;
var text = "";
for (; i < len; i++) { text += positions[i] + "
"; } document.getElementById("demo2").innerHTML = text;

Demonstration

A list of foward rugby positon in order from numbers 1-8:

Exercise 6

Problem Statement

Write a program using decision (if statements) that when a number is entered, the corresponding month shows.

Plan:

Ask the user to enter a number to receive a month.

Solution

function myFunction() {
var month = document.getElementById('numb').value;
var greeting;
if (month == 1) {
greeting = "January";
} else if (month == 2) {
greeting = "February";
} else if (month == 3) {
greeting = "March";
} else if (month == 4) {
greeting = "April";
} else if (month == 5) {
greeting = "May";
} else if (month == 6) {
greeting = "June";
} else if (month == 7) {
greeting = "July";
} else if (month == 8) {
greeting = "August";
} else if (month == 9) {
greeting = "September";
} else if (month == 10) {
greeting = "October";
} else if (month == 11) {
greeting = "November";
} else if (month == 12) {
greeting = "December";
} else {
greeting = "Incorrect input.";
}
document.getElementById("whatMonth").innerHTML = greeting;
}

Demonstration

Projects

Scratch

Scratch is a programming language developed by MIT that allows children and adults to learn how to think creatively in the early stages of programming. People all over the world can create games, stories, and other animations using it.

My Scratch Projects