Created
March 1, 2018 02:33
-
-
Save bahodge/775f84648b3f3d6e0939ad838886cdeb to your computer and use it in GitHub Desktop.
JavaScript - Statements practice with solutions included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//########### Cool guy statements ########## | |
//1.Declare 2 variables named {num1} and {num2} that are of type number. (Give them numerical values). | |
var num1 = 2; | |
var num2 = 5; | |
//2.Add num1 and num2 and display the result in the console. store the sum in a new variable called num3; | |
console.log(num1 + num2); | |
var num3 = num1 + num2; | |
//3. take the num3 and multiply it by double num1. Divide the new result by num2; Log the result; | |
console.log((num3 * (num1 * 2)) / num2); | |
//4. Create 3 new variables called string1, string2 and string3 assign a string to each. | |
//give each variable a string value; Something like s1 = I, s2 = am, s3 = hackerman! | |
var string1, string2, string3; | |
string1 = "I "; | |
string2 = " am "; | |
string3 = " HACKERMAN!"; | |
//5. Concatenate all three strings together and log it in the console. | |
console.log(string1 + string2 + string3); | |
//6. Store this new result in a statement; | |
var newString = string1 + string2 + string3; | |
//7. create a new number variable that stores a number. Concat the new number with the provided string below. | |
var myFavoriteNumber = 10; | |
var myString = "This is my new favorite number: "; | |
myString += myFavoriteNumber; | |
//8. Create a new statement that uses 4 variables displays a phone number in the proper format 123-456-7890; | |
//create the alternate versions as well 1-234-567-8901, (123)-456-7890 | |
var firstNumGroup = 123; | |
var secondNumGroup = 456; | |
var thirdNumGroup = 7890; | |
var hyphon = "-"; | |
console.log(firstNumGroup + hyphon + secondNumGroup + hyphon + thirdNumGroup); | |
//Assign this new phone number to a variable | |
//9. Write a statement that converts two negative numbers to positive numbers, add them together and then print the sum to the console.; research Math.abs. Math is fucking amazing; | |
console.log(Math.abs(-10) + Math.abs(-20)); | |
//10. Create a variable that holds a number. Create a variable that holds a string. create a variable that holds a boolean (T/F). | |
//Write the following: | |
//console.log(typeof (numbervariable)); //"number" | |
//console.log(typeof (stringvariable)); // "string" | |
//console.log(typeof (booleanvariable)); // "boolean" | |
//concat the number variable to the string variable and store it in a new variable called concatStringNum; | |
//console.log(typeof (concatStringNum)); | |
//what is the type? | |
//How would this be useful/terrible? | |
//HAIL THE DARK LORD!!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment