Professional Documents
Culture Documents
Build Software Applications
Build Software Applications
Documentation
HTML
HTML
Basic HTML
Lists
Tables Full list of HTML elements
Input
As a reminder, in most browsers you can right-click on a page and select View Source to see the HTML
CSS code used to render the page.
https://www.dukelearntoprogram.com/course1/doc/ 1/15
6/28/2020 Build Software Applications
smaller heading
<b>bold</b>
<b> Apply bold formatting to text
bold
<em>emphasis</em>
<em> Apply emphasis to text
emphasis
<img src="http://bit.ly/1QfkvVw"
Inserts an image. width="100px">
HTML src is the link specifying the image to
Basic HTML display (it is a required attribute)
Lists
<img> width (and height) specifies the size of
Tables the image (it is an optional attribute)
Input
Unlike most other tags, this start tag does not
CSS have a corresponding end tag.
Background Information
Tag Description Example
What is a Pixel? List item.
Transparency: Alpha Channel <li> <li>HTML</li>
List items can go inside unordered list, <ul>, or ordered list, <ol> tags.
Image Coordinate System
<ul> Unordered list, each item has a bullet point. <ul>
<li>HTML</li>
<li>CSS</li>
</ul>
HTML
https://www.dukelearntoprogram.com/course1/doc/ 2/15
6/28/2020 Build Software Applications
CSS
<ol>
<li>HTML</li>
<li>CSS</li>
<ol> Ordered list, each item has a number. </ol>
1. HTML
2. CSS
HTML
content
</td>
</tr>
</table>
heading
content
Input
HTML
Because the attributes used with input elements varies so much depending on the type of input you
Basic HTML want to use, we have provided several specific examples of using different types of input.
Lists
Tables Example Description
Input
What is a Pixel?
Transparency: Alpha Channel <input type = "range" type is slider
Image Coordinate System min = "10" min is minimum value, max
max = "100" is maximum value
value is default value
value = "10"
id lets us refer to input
id = "sldr"
element in JavaScript
oninput = "dosquare()"> oninput is event handler,
specifies to call dosquare
https://www.dukelearntoprogram.com/course1/doc/ 4/15
6/28/2020 Build Software Applications
Standard JavaScript
CSS
Arithmetic Operations
Comparing Two Numbers
Combining Comparisons Full list of CSS properties
Math Functions Mozilla color picker tool
Random Functions
This website challenges people to use CSS to make as many different stylized versions as possible
Background Information using the same HTML code.
12pt p {
font-size 16px text font-size: 14pt;
100% }
left td {
HTML right
text-align text text-align: center;
center
Basic HTML
justify
}
Lists
Tables
Input
blue body {
background- table, table cell, page
CSS rgb(0,0,255) background-color: #00FF00;
color backgrounds
#0000FF }
CSS Properties and Values
Standard JavaScript
td {
tables, table cells,
height 100px height: 10px;
images
}
https://www.dukelearntoprogram.com/course1/doc/ 6/15
6/28/2020 Build Software Applications
solid table {
border- tables, table cells,
dotted border-style: solid;
style images
dashed }
HTML
CSS
5px table {
CSS Properties and Values 10px dotted tables, table cells,
border border: 2px solid red;
5px dashed images
Course Specific Functions green
}
SimplePixel
SimpleImage
Printing table {
border-
collapse table border-collapse: collapse;
collapse
Standard JavaScript }
Arithmetic Operations
Comparing Two Numbers
Combining Comparisons
Math Functions
Course Specific JavaScript Functions
Random Functions
SimpleImage
https://www.dukelearntoprogram.com/course1/doc/ 8/15
6/28/2020 Build Software Applications
For these examples, assume the variable logo has the value of the image "devil.png" below. It is 100
pixels wide and 85 pixels tall.
https://www.dukelearntoprogram.com/course1/doc/ 9/15
6/28/2020 Build Software Applications
image's height, or
number of pixels
in the Y direction
returns the pixel in
logo.getPixel(0, 0) is the pixel (255, 255,
getPixel(x,y) this image at the
255, 255)
coordinate (x, y)
Standard JavaScript
Arithmetic Operations
HTML + addition 4 + 5 is 9
- subtraction 9 - 5 is 4
Basic HTML
Lists * multiplication 3 * 5 is 15
Tables
Input 6 / 3 is 2
/ division
6 / 4 is 1.5
CSS
% mod/remainder 5 % 3 is 2
CSS Properties and Values
SimplePixel
Operator Description Example
SimpleImage
Printing == is equal to 3 == 3 is true
https://www.dukelearntoprogram.com/course1/doc/ 11/15
6/28/2020 Build Software Applications
&& returns true only if both parts of the comparison are true (x > 3 && x < 7) is true
(x > 3 && x > 7) is false
! reverses the boolean value of a comparison (! x == 5) is false
Math Functions
Background Information
What is a Pixel?
What is a Pixel?
Transparency: Alpha Channel Digital images are made of pixels. A pixel is a small point of colored light. When you look at a computer
Image Coordinate System monitor, the image you see is actually made of a grid of these tiny dots of light. They are so small and
so close together that it looks like one continuous picture. To get an idea of how small a pixel is, the
monitor that I happen to be using as I write this has a resolution of 1440 x 900 (read as "1440 by
900"). That means that there are 1,440 pixels across the top and 900 pixels down one side, for a total
of almost 1.3 million pixels.
https://www.dukelearntoprogram.com/course1/doc/ 12/15
6/28/2020 Build Software Applications
This is what pixels might look like if they were magnified. This is an example of a 5x4 image because it
is 5 pixels wide and 4 pixels tall.
HTML Each pixel has a color value. We need a way to represent colors so that we can tell the computer which
color to make each pixel. There are many color representations, but JavaScript uses a scheme called
Basic HTML
the RGBA color model. Basically, it means that a color is represented by four numbers:
Lists
Tables R (the amount of red light)
Input G (the amount of green light)
B (the amount of blue light) and
CSS
A (called "alpha", this number tells how transparent the color
CSS Properties and Values should be)
Course Specific Functions So each color is represented by these four numbers ("Everything's a
number", remember?). Moreover, each of these number slots must
SimplePixel have a value between 0 and 255. You may be wondering whether
SimpleImage or not only 256 possibilities for each slot is enough to make all the
Printing many colors that we might want. If you have 256 possibilities for each
of the R, G, and B values, (ignoring the transparency number for now)
Standard JavaScript then the total number of colors available is over 16 million! It is
estimated that the human eye can only detect 10 million different
Arithmetic Operations colors, so there's no worry that you won't be able to make any color you want.
Comparing Two Numbers
Combining Comparisons Since the computer uses light to make a picture, the RGBA model is an additive color model. This
Math Functions means that the more the medium is added, the closer the color gets to white. Contrast this with using
Random Functions paint as a medium. That is a subtractive color model because the more paint you add, the further you
get from white. So it should come as no surprise then that a color with R, G, and B values all 0 is black
Background Information (no light) and a color with R, G, B values all 255 is white (pure light). Think of these numbers as knobs
that you can turn up or down. If you turn on the red and blue lights and leave off the green light, you
What is a Pixel? have shades of purple (R = 150, G = 0, B = 150, for example). The more you turn up the light, the
Transparency: Alpha Channel higher the number goes and the brighter the color gets. How will you know what values to use for R, G,
Image Coordinate System and B to make the color you want? If you search for "RGB color chart" on the Internet you will find lots
of sites with palettes of colors and their corresponding values.
https://www.dukelearntoprogram.com/course1/doc/ 13/15
6/28/2020 Build Software Applications
SimplePixel
SimpleImage
Printing
Standard JavaScript
Arithmetic Operations
Comparing Two Numbers
Combining Comparisons
Math Functions
Random Functions
Background Information
What is a Pixel?
Transparency: Alpha Channel
Image Coordinate System
All of the discussion so far has been generic knowledge of a computer representation of images and
colors. In other words, the same information would probably apply if you were programming in a
language other than JavaScript. The rest of this page gives you details that are specific to JavaScript
and the problems you are asked to solve.
https://www.dukelearntoprogram.com/course1/doc/ 14/15
6/28/2020 Build Software Applications
Material accessible from this webpage developed by the instructors at Duke University is licensed under a Creative Commons Attribution 4.0
International License.
HTML
Basic HTML
Lists
Tables
Input
CSS
SimplePixel
SimpleImage
Printing
Standard JavaScript
Arithmetic Operations
Comparing Two Numbers
Combining Comparisons
Math Functions
Random Functions
Background Information
What is a Pixel?
Transparency: Alpha Channel
Image Coordinate System
https://www.dukelearntoprogram.com/course1/doc/ 15/15