text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
we can begin to allow our JavaScript
349.58
4.05
code to respond to how the user is
351.38
4.29
actually interacting with our web page
353.63
3.72
to say when the user clicks on a button
355.67
3.56
I would like to run this particular
357.35
5.4
JavaScript function for example so let's
359.23
5.29
go ahead and give that a try I'll go
362.75
3.99
ahead and now instead of just saying
364.52
4.86
alert hello world let me put this alert
366.74
4.74
inside of a function and to create a
369.38
4.17
function in JavaScript you just use the
371.48
4.41
keyword function followed by the name of
373.55
3.54
the function I'll call the function
375.89
3.03
hello for example and then in
377.09
3.84
parenthesis any inputs that function
378.92
3.75
takes this hello function is not going
380.93
3.18
to take any input so I'll just use an
382.67
4.53
empty set of parentheses and then inside
384.11
5.82
of curly braces I include any of the
387.2
5.04
code that I want to run in this function
389.93
5.01
and so what I've done here now is create
392.24
5.1
a function called hello and then inside
394.94
3.87
of the curly braces have defined the
397.34
3.06
body of the function what code should
398.81
3.93
run when I run the hello function and
400.4
4.71
what the hello function should do is it
402.74
3.96
should display an alert that in this
405.11
4.59
case says a hello world so now what I'd
406.7
5.88
like to do is get this function to run
409.7
5.46
when something happens on the page for
412.58
5.37
example when a user clicks on a button
415.16
4.08
so to do that the first thing I'll need
417.95
3.69
to do is actually create a button so add
419.24
4.56
a button that just says like click here
421.64
5.82
for example so now if i refresh this
423.8
7.44
page i now see that i have hello and I
427.46
5.01
also have this button that says click
431.24
3.69
here but when I click here like nothing
432.47
3.69
happens I'm clicking the click here
434.93
2.46
button but it's not changing anything
436.16
3.24
because I haven't yet said what should
437.39
4.56
happen when the user does click on this
439.4
4.71
button and so one way we could do this
441.95
5.1
is by adding an attribute to this HTML
444.11
6.66
element called unclick what this is
447.05
5.97
going to do is it's going to add an on
450.77
3.99
click handler to this button it's going
453.02
3.48
to say what should happen when the user
454.76
3.96
clicks on this button and I'm going to
456.5
4.19
set the onclick attribute equal to
458.72
5.13
running the function hello and in order
460.69
4.84
to run a function in JavaScript just as
463.85
3.42
you ran a function with Python you use
465.53
3.81
the name of the function followed by a
467.27
3.81
set of parentheses to say go ahead and
469.34
3.75
actually run this function using this
471.08
3.93
parenthesis calls the function another
473.09
3.54
word for running the function and the
475.01
2.97
fact that there's nothing in between the
476.63
2.82
parentheses means we're not providing
477.98
3.63
anything as input to the hello function
479.45
3.72
though if the hello function did take
481.61
3.6
inputs we could certainly add that in
483.17
5.46
between the parentheses so now I've tied
485.21
5.31
the two pieces of this page together I
488.63
3.69
have a button that says click here and
490.52
4.62
I've added an onclick handler that says
492.32
4.26
that when you click on the button you
495.14
4.05
should run the hello function and then
496.58
4.14
up above I've defined the hello function
499.19
3.54
to say what should the hello function do
500.72
3.93
well when the function is called we're
502.73
3.57
going to display an alert that in this
504.65
4.56
case says hello world so now we should
506.3
6.63
be able to refresh the page we still see
509.21
5.22
the same thing at least initially where
512.93
2.85
it just says hello and a button that
514.43
4.2
tells me to click here but now if I go
515.78
3.93
ahead and click the button that says
518.63
3.57
click here well then I get the alert
519.71
4.74
that says this page says hello world I
522.2
4.38
can press ok and this event handler is
524.45
3.36
always going to work I click the button
526.58
3.24
again and I get the alert a second time
527.81
3.24
because every time I click the button
529.82
2.94
it's going to call the hello function
531.05
3.66
again and when I click the hello when
532.76
3.69
the hello function runs and it is going
534.71
5.4
to display this particular alert so this
536.45
5.85
now appears to give us a fair amount of
540.11
4.68
power and much as in other programming
542.3
4.35
languages languages like Python or other
544.79
3.03
languages you might have worked with
546.65
3.39
JavaScript has all these same types of
547.82
3.8
language features so far
550.04
3.41
we've seen datatypes things like a
551.62
3.51
string but we also have other data types
553.45
3.33
that we'll take a look at soon too we've
555.13
3.48
seen functions some functions that are
556.78
3.6
built into JavaScript like the alert
558.61
3.66