Skip to content

Devon's Lab #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ <h1>LAB | JS Data Types</h1>
<br />
<p> Open the <a href="https://developer.chrome.com/docs/devtools/open/">Dev Tools console</a> to see the console output.</p>

<script src="index.js"></script>
<script src="./script.js"></script>
</body>
</html>
202 changes: 126 additions & 76 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,126 @@
/*******************************************
Iteration 1.1 | Tongue Twister
*******************************************/
const s1 = "Fred";
const s2 = "fed";
const s3 = "Ted";
const s4 = "bread";
const s5 = "and";

// Concatenate the string variables into one new string


// Print out the concatenated string




/*******************************************
Iteration 1.2 | Camel Tail
*******************************************/
const part1 = "java";
const part2 = "script";

// Convert the last letter of part1 and part2 to uppercase and concatenate the strings


// Print the cameLtaiL-formatted string




/*******************************************
Iteration 2.1 | Calculate Tip
*******************************************/
const billTotal = 84;

// Calculate the tip (15% of the bill total)


// Print out the tipAmount




/*******************************************
Iteration 2.2 | Generate Random Number
*******************************************/

// Generate a random integer between 1 and 10 (inclusive)


// Print the generated random number



/*******************************************
Iteration 3.1 | Booleans
*******************************************/

const a = true;
const b = false;

// Try and guess the output of the below expressions first and write your answers down:
const expression1 = a && b;

const expression2 = a || b;

const expression3 = !a && b;

const expression4 = !(a && b);

const expression5 = !a || !b;

const expression6 = !(a || b);

const expression7 = a && a;
//strings
// let const and var
// const is always a constant meaning it never changes
// let is a variable that can be reasigned
const petName = "Ragnar's favorite toy";
const ownerName = `Joshua`;
const thePetLength = petName.length;
// console.log("hello", thePetLength);

//with variable names in JS, we use the 'camelCase' notation
//other naming conventions
// PascalCase
// kebab-case-like-this
// snake_case_is_like_this

//number variables
const petAge = "4";
const decimal = 4;
//remember numbers do not have a length property
// console.log(decimal.length);
const emptyString = 0;
//booleans
const isAGoodBoy = false;
// console.log(emptyString == false);

const users = ["Rishi", "Ragnar", "Joshua"];
//Math object
//random number between zero and one
const randomNumber = Math.random();
const decialNumber = 2.51;
const roundedNumber = Math.round(2.4999999999);
const ceilNumber = Math.ceil(3.00000001);
const floorNumber = Math.floor(7.9999999999999);
const smallestNumber = Math.min(2, 333, 5000, 2.1);
const largestNumber = Math.max(1, 4, 500, 10000);
// console.log(largestNumber);

//string methods
const dogName = "ragnar";
//index notation
const firstLetter = dogName[1];
//toUpperCase()
const capitalName = dogName[0].toUpperCase() + dogName.slice(1);

//mathematical operations

//raised to power
const num = 3 ** 3;
//modulo operator
const isEven = 33 % 2;
const isTrue = true;
// OR operator is ||
// console.log(!isTrue && num === 27);

//loops
const user = "Joshua";
let kebabCase = "";
//for loop needs three arguments...
//first is the starting value, second is until when to run the loop, third is how much to increment the loop
for (let i = 0; i < user.length; i++) {
// console.log(user[i] + "-");
if (i < user.length - 1) {
kebabCase += user[i] + "-";
} else {
kebabCase += user[i];
}
}

const newName = "Roberto";
let reversedName = "";
// console.log(kebabCase);
//for loop in reverse
for (let i = newName.length - 1; i >= 0; i--) {
// console.log(newName[i]);
reversedName += newName[i];
}
// console.log(reversedName);

//FIZZ BUZZ Challenge :)
//write a loop that counts to 100 from 0
//if the number is divisible by 3 then you should log 'FIZZ'
//if the number is divisible by 5 then you should log 'BUZZ'
//if the number is divisible by 3 and 5 then you should log 'FIZZ BUZZ'
//else you should just log the number

for (let i = 1; i <= 30; i++) {
if (i % 15 === 0) {
console.log("Fizz Buzz");
} else if (i % 3 === 0) {
console.log("Fizz");
} else if (i % 5 === 0) {
console.log("Buzz");
} else {
console.log(i);
}
}

// //with Switch statement
for (let j = 0; j <= 30; j++) {
switch (true) {
case j % 15 === 0:
console.log("FUZZ BUZZ");
break;
case j % 3 === 0:
console.log("FIZZ");
break;
case j % 5 === 0:
console.log("BUZZ");
break;

default:
console.log(j);
break;
}
}

let test = "hello";
let test2 = "world";
const concatenated = test + " " + test2;
const withTemplateLiterals = `hi ${test} ${test2} `;
console.log(withTemplateLiterals);

//cal a tip
const total = 84;
const tip = total * 0.15;
console.log(total + tip);