/
madlibs.html
123 lines (106 loc) · 3.56 KB
/
madlibs.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Fjalla+One' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<style>
input {
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: gray;
border: 0;
border-color: rgba(21, 153, 87, 0.2);
border-style: solid;
border-width: 2px;
border-radius: 0.3rem;
transition: color 0.2s, background-color 0.2s, border-color 0.2s;
font-size: 16px;
text-align: left;
border-radius: 5px;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 10px;
padding-right: 100px;
}
.prompt {
font-family:'Fjalla One';
font-size:40px;
padding-top: 2rem;
border-top: solid 1px #eff0f1;
}
.fill {
background: #ecf0f1;
color: #159957;
border-bottom: 2px black solid;
font-family: 'Shadows Into Light';
padding: 0 6px;
margin: 4px;
}
</style>
</head>
<body>
<div class="page-header">
<h2 class="project-name">Project 5: Mad Lib Game</h2>
<h2 class="project-tagline">This project involves the JS data type "Arrays", counting with JS, translating JS into HTML, if/else statements and more.</h2>
<a href="https://bulentkeles.github.com/GADash/" class="btn">go back</a>
</div>
<div class="main-content">
<h3>Objective</h3>
<li>Build an array to hold data</li>
<li>Write a button to move through the array</li>
<li>Write and if/else statement</li>
<li>Capture and return answers via JS</li>
<li>Build a basic game using JavaScript + CSS</li>
<h3>Example</h3>
<div class="prompt"></div>
<button class="button2">Next</button>
<footer class="site-footer">
<span class="site-footer-owner"><a href="https://bulentkeles.github.com/GADash">Dash Projects</a> is maintained by <a href="https://github.com/bulentkeles">bulentkeles</a>.</span>
</footer>
</div>
<script>
// List of prompts for the user
var prompts = [
'Type your name',
'Type an adjective',
'Type a noun'
];
var answers=[];
// Keep track of current prompt we're on
var currentPrompt = 0;
// A function that will call the next prompt
var nextPrompt = function() {
//if there's no answer in the form
if (currentPrompt != 0){
answers.push($('input').val());
}
// if there is a next prompt
if (currentPrompt < prompts.length) {
// put first prompt in all html elements with class
$('.prompt').html(prompts[currentPrompt] +'<br><input type="text">');
// move the next prompt into variable currentPrompt
currentPrompt = currentPrompt + 1;
}
//or else if we're at the end of the array
else {
// put a new message into the html.
showFinal();
}
}
//puts user answers into HTML
var showFinal = function() {
$('.prompt').html('This is the story of <span class="fill">'+answers[0]+'</span> and the <span class="fill">'+answers[1]+'</span> <span class="fill">'+answers[2]+'</span>.');
$('button').hide();
}
// run nextPrompt function when button is clicked
$('button').click(function() {
nextPrompt();
});
// Show the first prompt as soon as js loads
nextPrompt();
</script>
</body>