<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 num1 = prompt("What is 5 plus 5?"); // this is my prompt
var num2
var total
console.log("The variable 'total'is of type "+ typeof total);
total = Number(total);// making the variable into a number.
console.log("After the Number() the vaiable 'total' is a type "+ typeof total);
total = ('5 + 5');
console.log("The total is" + total);
// Insert your code for #2 here
// Insert your code for #3 here
// Insert your code for #4 here
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.