Javascript Notes – One

List of declared keywords.

Good basic steps to remember

 // 1. Declare variables and capture input.
const adjective = prompt("Give me a compliment");
console.log( adjective );
// 2. Combine the input with other words to create a story.
const compliment = `<p>You are so right I am: ${adjective} just the so ...</p>`;
console.log( compliment );
// 3. Display the story as a <p> inside the <main> element.
let wordvomit = compliment + "LIES LIES LIES!!!";
let spreadwordvomit = wordvomit;
console.log( spreadwordvomit );
document.querySelector('main').innerHTML = spreadwordvomit ;

to string literal

const flavor = "Blueberry";
const type = "Smoothie";
const price = 4.99;

const drink = flavor + ' ' + type + ': ' + '$' + price;

CHANGE

const flavor = "Blueberry";
const type = "Smoothie";
const price = 4.99;

const drink = `${flavor} ${type}: $${price}`;

CONDITIONALS

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>JavaScript Basics</title>
    <link href="css/style.css" rel="stylesheet"> 
  </head>
  <body>
    <main></main>
    <script src="js/conditionals.js"></script>  
  </body>
</html>

/* ---------------------
JS START
------------------------ */

if () {
  
} else {
  
}

/* ---------------------
RESULT
------------------------ */

const planet = prompt("Name a Planet");
if ( planet.toUpperCase() === "PLANET" ) {
  console.log( `${planet}: is not a planet` );
} else {
  console.log( "DUNCE!" ); 
}


/* ---------------------
ROUND 2
------------------------ */


const planet = prompt("Name a Planet");
if ( planet.toUpperCase() === "PLANET" ) {
  console.log( `${planet}: is not a planet!` );
} else {
  console.log( "better you got it wrong" ); 
}
let correctGuess = false;
const number = 6;
const guess = prompt("Guess a number between 1 and 10.");

if ( +guess === number ) {
  correctGuess = true; 
} 
if ( correctGuess === true ) {
  console.log('magical mind');
} else {
 console.log(`WRONG - you suck! you guessed ${guess} - it was ${number} douche!`); 
}

ELSE IF

if () { // must start with if end in else 
  
} else if () { // not tested if first is false
  
} else if () { // not tested if 2mnd is false
  
}
// neither are true - end in 
  else {
    
  }

const weather = prompt("what's falling outside?");
if ( weather === 'sun' ) { 
  console.log("It's buring my skin");
} else if ( weather === 'rain' ) { 
  console.log("I need to be hungover" );
} else if ( weather === 'men') { 
  console.log("YAY!! It's raining men" );
}
// neither are true - end in 
  else {
    console.log('dry - dry here');
  }

&& AND (logical) Operator

let age = 25;
( 20 < age && age < 30 )
true

let age = 35;
 CONDITIONAL   CONDITIONAL
( 20 < age && age < 30 )
false

|| OR (logical) Operator

agree = 'yes'
( agree === 'yes || agree === 'y' )
true

agree = 'n'
( agree === 'yes || agree === 'y' )
false

( password === '' || email === '' || phoneNumber === '' }
// any blanks makes true


print text to page

 // 1. Declare variables and capture input.
const adjective = prompt("Give me a compliment");
console.log( adjective );
// 2. Combine the input with other words to create a story.
const compliment = `

`You are so right I am: ${adjective} just the so …;`
 console.log( compliment ); // 

3. Display the story as a
<p> inside the main element.

let wordvomit = compliment + “LIES LIES LIES!!!”; document.querySelector(‘main’).innerHTML = wordvomit ; 

(where main is an html element on the page)