-
Notifications
You must be signed in to change notification settings - Fork 1
/
practice.js
81 lines (74 loc) · 2.25 KB
/
practice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// (example) Write a function that accepts two number arguments and adds them
// together.
function add(a, b) {
var sum = a + b;
return sum;
};
console.log(add(2,3));
// Create a function that takes in a cost and a quantity and outputs the total
// pre-tax cost for that quantity of items at the given price. For example
//
// var preTaxTotal = totalCost(5, 5.99); // 5 items at 5.99
// //=> 29.950000000000003
function totalCost(quantity, price) {
var total = quantity * price;
return total;
};
console.log(totalCost(5,5.99));
// Write a function that takes a rank and a suit as input, and returns a string
// representation of a card. For example, it should behave as follows
//
// cardString("ace", "spades");
// //=> ace of spades
//
// cardString("queen", "hearts");
// //=> queen of hearts
function cardString(rank, suit) {
var cardString = rank + " of " + suit;
return cardString;
};
console.log(cardString("ace","spades"));
// Write a function called `openTag` that accepts a tag name and returns an
// opening HTML tag with that tag name. For example,
//
// openTag("p");
// //=> <p>
//
// openTag("div");
// //=> <div>
function openTag(tag) {
var open = "<" + tag + ">";
return open;
};
console.log(openTag("div"));
// Similarly, write a function called `closingTag` that returns the closing HTML tag
// with that name.
//
// closeTag("p");
// //=> </p>
//
// closeTag("div");
// //=> </div>
function closeTag(tag) {
var close = "</" + tag + ">";
return close;
};
console.log(closeTag("div"));
// Write a function called `toTagString` that accepts two inputs: a tag name,
// and the string content, and returns the content tagged with the specified
// string. For example:
//
// toTagString("li", "list item 1");
// //=> <li>list item 1</li>
//
// // the 'em' tag is for 'emphasis'
// toTagString("em", "this is important stuff");
// //=> <em>this is important stuff</em>
//
// Although I won't be testing for this, your code should re-use the functions that
// you created in the previous section.
function toTagString(tag, content) {
var result = openTag(tag) + content + closeTag(tag);
return result;
};
console.log(toTagString("em","this is important stuff"));