Practice Set - Basic Math and String Operations

by Ramya Ranganathan

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>
        Click Me #2 button. <br>
      <input id="input1" type="number"><input id="input2" type="number"><br>
      <div>Your total is: <span id="resultArea"></span></div>
      <div id="clickme2" class="hwbutton">Click Me #2</div>
      <br>
      <br>
    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
 	// get the values from the three text fields
 	var val1 = document.getElementById("input1").value;
 	var val2 = document.getElementById("input2").value;
 	var val3 = document.getElementById("input3").value;

 	//check that they are integers, otherwise make them zero
 	val1 = (parseInt(val1) ? parseInt(val1) : 0);
 	val2 = (parseInt(val2) ? parseInt(val2) : 0);
 	val3 = (parseInt(val3) ? parseInt(val3) : 0);

 	// add the three values
 	var total = val1 + val2

    alert(total)

// Insert your code for #2 here



// Insert your code for #3 here



// Insert your code for #4 here