Skip to content
Permalink
5d3dac86ba
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
43 lines (35 sloc) 1.32 KB
/* 1)
Write a function that calcuates and RETURNS the product of two
numbers. I should be able to use the function like the code below:
*/
function getProduct(num1, num2) {
result = num1 * num2
return result
}
var prod = getProduct(5,8);
console.log(prod+5);
/* 2)
Write a Javascript function that takes TWO parameters: element and class.
The element should be a DOM object, NOT a string. The class can be a string.
The function should add the designated class to the element. The code below should work */
function addClassToElement(ele, cl) {
ele.className += " " + cl;
}
// function fancyLog(text, element) {
// console.log(text);
// // Now what goes in here?
// var element = document.createElement(element);
// element.innerHTML = text;
// document.querySelector("#log").appendChild(element);
// }
var p = document.getElementById("item");
addClassToElement(p, "class1");
/* 3)
A function that creates any type of element given, adds content to it, and adds it to the page in an intended parent. The code below should work. The PARENT should be a DOM object, not a selector. */
function addItemToParent(ele, text, parent) {
var ele = document.createElement(ele);
ele.innerHTML = text;
parent.appendChild(ele);
}
var parent = document.getElementById("container");
addItemToParent("h1", "This is some content",parent);