Skip to content
Open
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
91 changes: 87 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
/************************************************************** Task 1: Warm-up! **************************************************************/
//Task a: declare a variable called votingAge, console log true if age > 18 (no function required)



var votingAge = 29;
if (votingAge > 18){
console.log(true)
}


//Task b: declare a variable and then use a conditional to change the value of that variable based on the value assigned to a second variable (no function required)

var num1 = 5
var num2 = Math.floor(Math.random()*10) + 1

if (num2 > 2){
let num1 = 6;
console.log(num1, num2);
}



//Task c: Convert string ("1999") to integer (1999) (no function required) // hint look up the Number method

var integer = parseInt(1999)
console.log(integer)




//Task d: Write a function to multiply a*b


var x = Math.floor(Math.random()*10)
var y = Math.floor(Math.random()*10)
var z = x * y
console.log(z)



Expand All @@ -29,6 +41,13 @@



var myAge = 22
var dogYears = 7
var newAge = myAge * dogYears
console.log(newAge)





/************************************************************** Task 3 **************************************************************/
Expand All @@ -53,6 +72,7 @@




/************************************************************** Task 4 **************************************************************/
// Rock, Paper, Sissors
// Your function should take a string (either rock paper or sissors)
Expand All @@ -61,6 +81,63 @@
// hint while you can complete this with only conditionals based on strings it may help to equate choice to a number


// var userChoice = prompt("Do you choose rock, paper or scissors?");

// var computerChoice = Math.random();
// if (computerChoice < 0.34) {
// computerChoice = "rock";
// } else if(computerChoice <= 0.67) {
// computerChoice = "paper";
// } else {
// computerChoice = "scissors";
// }


// var compare = function(choice1,choice2) {

// if (choice1 === choice2) {

// return "Tie";
// }

// else if (choice1 === "rock") {

// if (choice2 === "scissors") {
// return "rock wins";
// }
// else {
// return "paper wins";
// }
// }

// else if (choice1 === "paper") {

// if (choice2 === "rock") {
// return "paper wins";
// }
// else {
// return "scissors wins";
// }

// }

// else if (choice1 === "scissors") {

// if (choice2 === "rock") {
// return "rock wins" + "<br>";
// }
// else {
// return "scissors win";
// }
// }


// }


// document.write("Computer chose: " + computerChoice + "<br>");
// document.write(compare(userChoice,computerChoice));



/************************************************************** Task 5 **************************************************************/
Expand All @@ -69,6 +146,12 @@



var km = Math.floor(Math.random()*10 + 1)
var mi = km * .621371

console.log(km, mi)




//b. Feet to CM - should take the number of feet and convert it to the equal number of centimeters
Expand Down