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
190 changes: 165 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Do the following:
HINT: no function required
*/


const votingAge = 17;
console.log(votingAge>=18);

/*
Task 1b - Values
Expand All @@ -32,8 +33,16 @@ Do the following:
*/


let var1 = 21;
const var2 = 'I';

if (var2==='I') {
var1 = 'Ok';
} else {
var1 = 'Not Ok';
}

console.log(var1);

/*
Task 1c - Convert Strings to Numbers
Expand All @@ -46,7 +55,9 @@ Do the following:
HINT: look up the Number method
*/


const user_str = "1999";
let converted = parseInt(user_str);
console.log(converted-1);


/*
Expand All @@ -58,9 +69,11 @@ Do the following:
3. Multiply a and b and return the answer
*/

function multiply(/*add your code here*/){
/*add your code here*/
}
function multiply(a,b){
return a * b;
}

console.log(multiply(2,4));



Expand All @@ -74,10 +87,12 @@ Do the following:
3. Return the newly calculated age
*/

function dogYears(/*add your code here*/){
/*add your code here*/
function dogYears(humanAge){
return humanAge * 7;
}

console.log(dogYears(21));



/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/
Expand Down Expand Up @@ -107,10 +122,61 @@ Use the hungryDog function and feeding requirements below to do the following:
NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996
*/

function hungryDog(/*add your code here*/){
/*add your code here*/
function hungryDog(weight_value, age_value){
let food_value;

if (age_value >= 1) {

if (weight_value <= 5) {

food_value = weight_value * 0.05;

} else {

if(weight_value <= 10) {

food_value = weight_value * 0.04;

} else {

if(weight_value <= 15) {

food_value = weight_value * 0.03;

} else {

food_value = weight_value * 0.02;

}
}
}
} else {
if (age_value < (4/12)) {

food_value = weight_value * 0.1;

} else {

if (age_value < (7/12)) {

food_value = weight_value * 0.05;

} else {

if (age_value < 1) {

food_value = weight_value * 0.04;

}
}
}
}

return food_value;
}

console.log(hungryDog(15,1));



/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/
Expand All @@ -127,9 +193,53 @@ Use the game function below to do the following:
HINT: While you can complete this with only conditionals based on strings, it may help to equate choice to a number when using Math.random()
*/

function game(/*add your code here*/){
/*add your code here*/
let computer_choise = Math.random();
let computer_string = null;
if (computer_choise > 0 && computer_choise < (1/3)){
computer_string = 'rock';
}
if (computer_choise > (1/3) && computer_choise < (2/3)){
computer_string = 'paper';
}
if (computer_choise > (2/3) ){
computer_string = 'scissors';
}

function game(user_string, computer_string){
let result = null;

//game

if (computer_string === user_string) {
result = "it's a tie";
} else {
if (user_string === 'rock') {
if (computer_string === 'paper') {
result = 'you lose!';
} else {
result = 'you win!';
}
} else {
if (user_string === 'paper') {
if (computer_string === 'rock') {
result = 'you win!';
} else {
result = 'you lose!';
}
} else {
if (computer_string === 'rock') {
result = 'you lose!';
} else {
result = 'you win!';
}
}
}
}

return result;
}

console.log(game('rock', computer_string));



Expand All @@ -144,10 +254,11 @@ Using the miles function below do the following:
3. Return the number of miles
*/

function miles(/*add your code here*/){
/*add your code here*/
}
function miles(metric_system){
return metric_system * 0.621371;
}

console.log(miles(16));


//Task 5b - Feet to CM
Expand All @@ -158,10 +269,11 @@ Using the feet function below do the following:
3. Return number of feet
*/

function feet(/*add your code here*/){
/*add your code here*/
}

function feet(island_system){
return island_system / 30.48;
}

console.log(feet(1));


/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/
Expand All @@ -174,9 +286,13 @@ Using the annoyingSong function below do the following:
"(number) bottles of soda on the wall, (number) bottles of soda, take one down pass it around (number left over) bottles of soda on the wall"
*/

function annoyingSong(/*add your code here*/){
/*add your code here*/
function annoyingSong(starting_number){
for (starting_number; starting_number > 0; starting_number--) {
return `${starting_number} bottles of soda on the wall, ${starting_number} bottles of soda, take one down pass it around ${starting_number-1} bottles of soda on the wall`;
}
}

console.log(annoyingSong(5));


/*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/
Expand All @@ -194,12 +310,28 @@ Using the grade function below do the following:
below 60 = F
*/

function grade(/*add your code here*/){
/*add your code here*/
function grade(score){
let result = null;
if (score < 60) {
result = 'you got a F';
}
if (score < 70 && score >= 60) {
result = 'you got a D';
}
if (score < 80 && score >= 70) {
result = 'you got a C';
}
if (score < 90 && score >= 80) {
result = 'you got a B';
}
if (score < 100 && score >= 90) {
result = 'you got a A';
}
return result;
}



console.log(grade(76));


/*💪💪💪💪💪💪💪💪💪💪 Stretch 💪💪💪💪💪💪💪💪💪💪*/
Expand All @@ -215,10 +347,18 @@ Using the vowelCounter function below do the following:
*/


function vowelCounter(/*add your code here*/) {
/*add your code here*/
function vowelCounter(user_string) {
let count=0;
for(let i=0; i < user_string.length; i++) {
if (user_string.charAt(i) === 'a' || user_string.charAt(i) === 'A' || user_string.charAt(i) === 'e' || user_string.charAt(i) === 'E' || user_string.charAt(i) === 'i' || user_string.charAt(i) === 'I' || user_string.charAt(i) === 'o' || user_string.charAt(i) === 'O' || user_string.charAt(i) === 'u' || user_string.charAt(i) === 'U' || user_string.charAt(i) === 'y' || user_string.charAt(i) === 'Y') {
count++;
}
}
return count;
}

console.log(vowelCounter("Iaroslav"));



/*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/
Expand Down