-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (67 loc) · 2.26 KB
/
script.js
File metadata and controls
73 lines (67 loc) · 2.26 KB
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
/**
* Done: Update the text in the "Formatted Text" section as a user types in the textarea
* Done TOGETHER: Add a .bold, .italic classes to "Formatted Text" when the appropriate button is clicked
* Done: Add an .underline class to "Formatted Text" when Underline button is clicked
* Done: Toggle the align style for "Formatted Text" when the appropriate button is clicked
*/
/**
* Update the output text as a user types in the textarea
* HINT: Use the onkeydown function inside HTML
*/
window.onload= function(){
document.getElementById('text-input').value="";
}
function updateText(){
// CODE GOES HERE
let text = document.getElementById('text-input').value;
document.getElementById("text-output").innerText = text;
}
/**
* Toggle the bold class for the output text
* HINT: Use the onclick function insite HTML
* HINT: Look into using this keyword
* HINT: Use the classList property
* HINT: Toggle .active class for the button
*/
function makeBold(elem){
//CODE GOES HERE
elem.classList.toggle('active');
document.getElementById("text-output").classList.toggle('bold');
}
/**
* Toggle the italic class for the output text
*/
function makeItalic(elem){
elem.classList.toggle('active');
document.getElementById("text-output").classList.toggle('italic');
}
/**
* Toggle the underline class for the output text
* HINT: Toggle the .active class for the button
* HINT: Use the classList property
* HINT: Use contains, remove, and add functions
*/
function makeUnderline(elem){
//CODE GOES HERE
elem.classList.toggle('active');
let bool = document.getElementById("text-output");
if(bool.classList.contains("underline"))
bool.classList.remove("underline");
else
bool.classList.add("underline");
}
/**
* Toggle the style textAlign attribute
* Toggle the active state for the align butttons
* HINT: Use the style property of the element
* HINT: Make sure to untoggle the active state for all other align buttons
*/
function alignText(elem, alignType){
// CODE GOES HERE
document.getElementById('text-output').style.textAlign=alignType;
let alignList = document.getElementsByClassName('align');
for(let i=0;i<alignList.length;i++){
alignList[i].classList.remove('active');
}
elem.classList.add('active');
}