COMP4021 Internet Computing > Lab 1 - Guessing Game

Overview

Lab Instructions

1. The Guessing Game

2. The Title Screen and the Main Screen

<!-- the title screen -->
<div class="box" id="title">
    ...
</div>

<!-- the game screen -->
<div class="box" id="main">
    ...
</div>

2.1. Using Appropriate Styles for Both Screens

Making an Appropriate Screen Size
<div style="width: 50vw; height: 5vh"></div>
Putting the Screens Centrally
<div style="width: 50vw; height: 5vh; margin: 0 25vw"></div>
Adding a Black Border
<div style="width: 50vw; height: 5vh; border: 5px solid black"></div>
default box sizing

using border-box

Adjusting the Font Properties

3. The Title Screen

3.1. Using Appropriate Styles for the Title Screen

<!-- the title screen -->
<div class="box" id="title">
    ...
</div>
Using a Transparent Background
<div style="background: red; opacity: 0.5"><b>RED</b></div>
RED
<div style="background: rgba(255, 0, 0, 0.5)"><b>RED</b></div>
RED
Putting the Text Centrally
Changing the Font Appropriately
<p id="title1">Fantastic</p>
<p id="title2">Number</p>
<p id="subtitle">that <big>You Need</big><br>
    to <big>Guess</big></p>

4. The Main Screen

4.1. Using Appropriate Style for the Main Screen

<!-- the main screen -->
<div class="box" id="main">
    ...
</div>
Changing the Hyperlink to Look Like a Button
<a id="button" href="#">Enter Your Guess</a>

4.2. Hiding the Main Screen

5. The JavaScript Code

let answer;

function load() {
    ...
}

function start() {
    ...
}

function guess() {
    ...

    return false;
}

5.1. Making an Answer Using a Random Number

parseInt(Math.random() * 100) + 1

5.2. Completing the Click Handler of the Title Screen

<!-- the title screen -->
<div class="box" id="title">
    ...
</div>
document.getElementById("title").style.backgroundColor = "black";

5.3. Asking the Player for the Guess

<a id="button" href="#" onclick="return guess()">Enter Your Guess</a>

5.4. Handling the Player Guess

<p id="hint">Press the button to start the guess!</p>
document.getElementById("hint").innerHTML = "...";

6. Finishing the Game

Submission

You do not need to submit the lab. It would be very useful to save a copy of your work, e.g. in a USB or through email.