Practice Set - Basic Math and String Operations

by Tanveer Khan

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 firstNumber = 25;
   var secondNumber =35;
   var total = firstNumber + secondNumber;
   console.log(total); */


// Insert your code for #2 here
	 /* var someNumber = prompt("enter a number in the popup:");
	    someNumber = parseInt(someNumber);
	    someNumber = someNumber + 1;
	    console.log("total is: :" + someNumber); */
   


// Insert your code for #3 here
	 /* var srqRoot = Math.sqrt(36); // Using the Math object Math.sqrt to calculate the quare root of 36
	    console.log("Square root of 36 is: " + srqRoot); */


// Insert your code for #4 here
	 /* var date = prompt("What is today's date?"); 
	    console.log("The variable 'date' is of type "+ typeof date);
	    
	    date = date + 1;
	    console.log("Tomorrow's date will be: " + date) */
		var someText = prompt("Enter some text in the box"); // making the user enter some text in the popup
    console.log("The variable 'someText' is of type " + typeof someText); // checking what 
    someText = someText.length;
    console.log("length of the text is : " + someText);