JavaScript Flashcards
(58 cards)
create a dialouge box that says “Hello from Treehouse”
alert(“Hello from Treehouse”);
print to the page “Welcome to JavaScript Basics”
document.write(“<h1> Welcome to JavaScript Basics </h1>”);
add JavaScript to an HTML document
link a scripts.js file to an html file
print a “Start program” message to the console
console.log(“Start program”);
create a dialogue box which displays the contents of the var message
alert(message);
escape the apostrophe in She’s a great programmer.
She's a great programmer. (backslash is above Shift on the US keyboard)
capture visitor’s input by storing prompt data in a visitorName variable
var visitorName = prompt(‘What is your name?’);
create a var message that combines the greeting ‘Hello’ with the visitor’s name (var name) and “Welcome”;
var message = “Hello “ + visitor + “. Welcome”;
concatenation operator
+=
create a variable fullName which combines firstName and lastName
var fullName = firstName + “ “ + lastName;
print to the console var message converted to upper case
console.log(message.toUpperCase());
what is an integer?
a whole number without a decimal point (5, 10, etc.)
convert var totalBadges = HTMLBadges + CSSBadges from string to numbers
var totalBadges = parseInt(HTMLBadges) + parseInt(CSSBadges);
function for converting a string with integers to numbers
parseInt();
convert ‘1.25’ to numbers
parseFloat(‘1.25’);
round 4.5 to the nearest integer using a math method
Math.round(4.5);
erase all the data from the console
clear();
create a random number from 1 to 6 using Math.random
Math.floor(Math.random () * 6) +1;
create a random number within a range from bottomNumber to topNumber
var randomNumber = Math.floor(Math.randon() * (topNumber - bottomNumber +1)) + bottomNumber;
equality operator
===
write a conditional statement that gives to alternatives 1) Yes, that’s right 2) Sorry, that’s wrong to a question ‘What programming language is the name of a gem?
var message = prompt(‘What programming language is the name of a gem?’);
if (answer.toUpperCase === ‘RUBY’) { document.write(<p>“That’s right” </p>) } else { document.write(<p> Sorry. That’s wrong. </p>) }
single line comment
// This is a single line comment.
multiple line comment
/* This is a multiple line code . . . . . . . */