Week 3: Assignment 1

writing basic input and output code to the console

by Philippe Xantus

HTML

<h3>Basic Math and String Operations</h3>
<h4>4 Tasks for this Practice Set:</h4>
<ol>
    <li>
        Write a script to add two numbers and output the sum to the console</li><li>
    Write a script that prompts for input, adds one to whatever number was input and outputs the sum to the console. Use the increment operator.  Assume that the input will be a number (no type-checking is required for this exercise).
    </li><li>
    Look up the Math object, and use one of its methods to do <i>something</i> to a number and output the result to the console (you pick: square it, round a decimal number up or down, do a trig function...whatever) Make sure the you comment your code or use console output to describe what you’re doing.
</li><li>
    Prompt for input and assign the result to a variable. Then, look up the String object, and use one of its properties to output the length of the string variable to the console.
    </li>
</ol>

JavaScript

// Insert your code for #1 here

var numb1 = parseInt(prompt('Please enter your fist number'));
var numb2 = parseInt(prompt('Please enter your second number'));
var sum = numb1 + numb2;
console.log('The Sum Result is ' + sum);

// Insert your code for #2 here

var numb3 = prompt('Increment a number');
var increment = ++numb3
console.log('The increment is '+ increment);


// Insert your code for #3 here

var numb4 = prompt('Please enter number to be rounded');
console.log('Your result is '+ Math.ceil(numb4));

// Insert your code for #4 here

var string1 = prompt('let\'s count your Characters');
console.log('The number of letters in your sentence is '+ string1.length);