JavaScript
Overview of JavaScript and frontend programming
// define variable
const hello = "Hello World!";
//console.log to print output to console (in dev tools)
console.log(hello);
// defining a function
function printMessage(message) {
console.log(message);
}
// calling a function
printMessage("Hello from a function!");
// function to create data for person (from https://nighthawkcoders.github.io/APCSA//techtalk/javascript)
function Person(name, role) {
this.name = name;
this.role = role;
}
const womenInStem = [
new Person("Mads", "deployment"),
new Person("Meens", "backend"),
new Person("Prans", "scrum master"),
new Person("Shish", "frontend")
]
console.log(womenInStem)
// create object for listing
function Listing(name, price, contactInfo) {
this.name = name;
this.price = price;
this.contactInfo = contactInfo;
}
const data = [
new Listing("TINspire Calculator", "70.00", "test@test.com"),
new Listing("New PE Lock", "5.00", "1-800-YOUR-NUMBER"),
new Listing("AP Bio Prep Book", "15,00", "test@test.com")
]
// return table row for each listing that can be added to html
for (const row of data) {
const name = row.name;
const price = row.price;
const contactInfo = row.contactInfo;
console.log(`
<tr>
<td>${name}</td>
<td>${price}</td>
<td>${contactInfo}</td>
</tr>
`)
}