Saturday, April 5, 2014

NIIT Q1 ACTIVITY BOOK CHAPTER 8

Q1) You have been assigned a task to create a web page, sign in/up,
    in the skyLight university website. The sign In/Up web page contains two forms, create an account and sign in.
    The sign up form contains the Name, Password, and confirm paaword fields. Create an account form contains the name, password fields.
    you need to implement functionality in the create an account form in such a way that users' details
    are not stored locally if the browser is closed. However, if the browser is not closed, the users', details should be stored locally if the browser is
    closed. however, if the browser is not closed, the users' details should be stored locally if the
    browser is not closed. however if the browser is not closed, the users details should be
    stored locally and the password gets automatically filled in the password field of the sign in form
    when the user enters the name.the sign in/up web page is shown in the folllowing figure.




Ans1)



<html>
<link type="text/css" rel="stylesheet"href="ExternalStylesheet\homestylesheet.css'/>
<style>
th{
color:red;
}
#form2{
position:absolute;
top:50px;
left:400px;
width:320px;
height:200px;
border:3px solid red;
margin-left:190px;
}
#form2{
width:320px;
height:200px;
border:3px solid red;
margin-left:190px;
margin-right:50px;
}
button{
margin-left:80px;
color:white;
background-color:blue;
}
</style>
<SCRIPT>
function checksum()
{
 if (!form1.username.value.match(/^[a-zA-Z]+$/)&& form1.username.value !="")
   {
form1.username.value="";
form1.username.focus();
alert("please enter only alphabets in text");
   }
}








function checkpassword()
{
if(form1.pass1.value!=form1.pass2.value)
{
               alert("passwords entered do not match");
}
else
if(form1.pass1.value!=form1.pass2.value)
{
             alert("Passwords entered do not match");
}
else
if(typeof (Storage)!=="unidentified"){
                    sessionStorage.userid= form1.username.value;
                    sessionStorage.passwrd = form1.pass1.value;
                    alert("Registered");
      }
      }
function login()
{
       if(typeof(Storage)!=="underfined")
      {
       if (form2.username1.value==sessionStorageuserid){
         form2.pass3.value=sessionStorage.passwrd;
       }
       }
       }
       function onsubmit()
       {
       if((form2.usrname1.value!="")&&(form2.pass3.value==sessionStorage.passwrd))
                {
                 alert(Signed In");
                }
        else
        {
        alert("Password do not match");
        }
        }






</SCRIPT>
</HEAD>
<BODY>
<FORM id="form1" name="sign up" onsubmit="checkPassword()">
<TABLE>
<tr>
<th colspam="2">Create an Account</th>
</tr>
<tr>
<td>Name:</td><td><Input type="text" name="username" onkeyup="checkName();"required></td>
</tr>
<tr>
<td>Password:</td><td><Input type="password" name="pass1"required></td>
</tr>
<tr>
<td>Confirm Password:</td><td><Input type="password" name="pass2"required></td>
</tr>
<tr><td><BR><Button type="Submit"Register</td></tr>
</TABLE>
</FORM>
<FORM id="form2" name="Sign In" onsubmit="onSubmit();">
<TABLE>
<TR>
<TH colspan="2">Sign In</TH>
</TR>
<TR>
<TD>Name:</TD><TD><Input type="Text" name="username1" onkeyup="checkname();" onchange="login;" required></TD>
</TR>
<TR>
<TD>Password:</TD><TD><Input type="password" name name="pass3" required></TD>
</TR>
<TR><TD><BR><Button type="Submit">Sing In</TD></TR></TABLE>
</FORM>
</BODY></HTML>    

Friday, April 4, 2014

NIIT Q2 ACTIVITY BOOK CHAPTER 5 ADDING CONSTRAINTS

Question 2:  after creating the online registration form,you need to incorporate the following constraints on the form element:


Ans:-
<!DOCTYPE HTML>
<html>
<head><link type="text/css" rel="stylesheet" href="external stylesheet/homestylesheet.css"/>
<script>
function checkNum()
{
if(!form1.number.value.match</^[0-9]+$/) && form1.number.value !="")
   {
form1.number.value="";
form1.number.focus();
alert"please enter only number in text");
   }
}
function checkRoll()
{
if (!form1.roll.value.match(/^[0-9]+$) && form1.roll.value !="")
  {
from1.roll.value="";
from1.roll.focus();
alert("please enter only alphabets in text");
  }
}
function checkFirstName()
{
if (!form1.usrname.value.match(/^[0-9]+$) && form1.usrname.value !="")
  {
from1.usrname.value="";
from1.usrname.focus();
alert("please enter only alphabets in text");
  }
}
function checkLastName()
{
if (!form1.usrname1.value.match(/^[0-9]+$) && form1.usrname1.value !="")
  {
from1.usrname1.value="";
from1.usrname1.focus();
alert("please enter only alphabets in text");
  }
}
fucnktion check()
{
if((document.form1.usrname.value!="")&&(document.form1.usrname1.value!="")&&(document.form1.mail.value!="")&&(document.form1.roll.value!="")(document.form1.number.value!="")&&(document.form1.sel.value!="andro"))
{
alert("your detail has been saved.\nplease submit the course fee at the cash counter before 13-04-2013 and collect your id card.\nthe training will start on 23-04-2013 from 10:30am to 4:30pm.");
}
else if((document.form1.usrname.value!="")&&(document.form1.usrname1.value!="")&&(document.form1.mail.value!="")&&(document.form1.roll.value!="")(document.form1.number.value!="")&&(document.form1.sel.value!="java"))
{
alert("your detail has been saved.\nplease submit the course fee at the cash counter before 20-03-2013 and collect your id card.\nthe java training will start on 30-04-2013 from 10:30am to 4:30pm.");
}
else if((document.form1.usrname.value!="")&&(document.form1.usrname1.value!="")&&(document.form1.mail.value!="")&&(document.form1.roll.value!="")(document.form1.number.value!="")&&(document.form1.sel.value!="C"))
{
alert("your detail has been saved.\nplease submit the course fee at the cash counter before 20-04-2013 and collect your id card.\nthe Robotics training will start on 30-04-2013 from 10:30am to 4:30pm.");
}
else if((document.form1.usrname.value!="")&&(document.form1.usrname1.value!="")&&(document.form1.mail.value!="")&&(document.form1.roll.value!="")(document.form1.number.value!="")&&(document.form1.sel.value!="hack"))
{
alert("your detail has been saved.\nplease submit the course fee at the cash counter before 13-05-2013 and collect your id card.\n  training will start on 31-04-2013 from 10:30am to 4:30pm.");
}
}
</script>
<style>
button{
border:2px solid navy;
background:white;
height:40px;
width:120px;
border-radius:5px;
background-color:navy;
color:white;
}
h1{
text-color:navy;
padding-left:80px;
text-align:center;
}
td{
font-size:20px;
width:400px;
padding:5px;
}
form{
border:5px solid red;
}
h1{
color:#C71585;
}
table{
margin-right:400px;
margin-left:400px;
}
</style>
</head>
<body>
<form name="form1" onsubmit="check();">
<h1>Registration Online</h1>
<table>
<tr>
<td>First Name</td>
<td><input type="text" id="usrname" placeholder="enter your first name" onkeyup="checkFirstName();"required></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" id="usrname1" placeholder="enter your last name" onkeyup="checkLastName();"required></td>
</tr>
<tr>
<td>Email ID</td>
<td><input type="text" title="email" id="mail" placeholder="enter your email address" pattern="[^@]+@[a-zA-Z]+\.[a-zA-Z]{2,6}"required></td>
</tr>
<tr>
<td>Roll Number</td>
<td><input type="text" id="roll" placeholder="enter your roll number" onkeyup="checkRoll();"required></td>
</tr
<td>Training Program</td>
<td><select id="sel">
<option value="movie">Select Training </option>
<option value="andro">Android </option>
<option value="java">Java </option>
<option value="C">Robotics </option>
<option value="hack">Ethical Hacking </option>
</select></td>
</tr>
<tr>
<td>Contact Number</td>
<td><input type="num" id="number" onkeyup="checkRoll();" placeholder="enter your contact number" required></td>
</tr>
<tr><td>
<Button type="submit">Submit<Button></td>
<td><BUTTON type="reset">Reset</BUTTON></td>
</tr>
</table>
</form>
</body>
</html>

NIIT Q1 ACTIVITY BOOK CHAPTER 5 Online registration

Q1) SkyLight university organizes short term training programs for its existing students to enhance their technical and professional skills. For this, you need to create a web page named
    Register displaying the details about the training sessions in the upcoming weks. In addition, you need to add a link to the online registration form on the register web page.
    However, to participate in such programs, the sudents need to enroll by filling the online registration form. For this, you need to create a form that contains the following fields.
    *First Name
    *Last Name
    *Email ID
    *Training Program
    *Roll Number
    *Contact Number
 
 In addition, you need to add two buttons, Reset and submit, on the form, as shown in the following figure.

Ans1)


Type the code in Notepad and save the file as registration.html

<html>
<head><link type="text/css" rel="stylesheet" href="Externalstylesheet/homestylesheet.css"/>
<style>

table
{
border:solid 2px navy;
font-size:20px;
float:right;
}
th{
text-align:center;
padding:3px;
}
td
{
text-align:left;
padding:3px;
}
tr
{
background-color:white;
}
h1,img{float:right;}
a{font-family:futura MD bt;
font-weight:bold;
float:left;
font-size:20px;
position:relative;
left:1000px;
}
</style>
</head>
<body>
<table>
<tr><th><b>Training Sessions in the Upcoming Weeks</b></th></tr>
<tr>
<td>A two days training session on android this weekend. Interested candidates can apply.</td>
</tr>
<tr>
<td>training on ethical hacking from 30th march,2013 to 28th april,2013. Interested candidates can apply.</td>
</tr>
<tr>
<td>Live project Training on robotics from 5th April, 2013 to 30th April, 2013. Interested candidates can apply.</td>
</tr>
<tr>
<td>Live Project Training with certification on java in the upcoming months. Interested candidates can apply after 31st may,2013.</td>
</tr>
 </table>
<br><br><br><br><br><br><br><br><br><br>
<a href="onlineregistrationfrom.html" target="frame4"><img src="images\Register Me.png" width=170 height=120</img></a>
</body>
</html>





Type the code in Notepad and save the file as onlineregistrationform.html


<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="ExternalStylesheet/homestylesheet.css"/>

<style>
button{
border:2px solid navy;
background:White;
height:40px;
width:120px;
border-radius:5px;
background-color:navy;
color:White;
}
h{
text-color:navy;
padding-left:80px;
text-align:center;
}
td{
font-size:20px;
width:400px;
padding:5px;
}
form{
border:5px solid red;
}
h1{
color:#C71585;
}
table{
margin-right:400px;
margin-left:400px;
}
</style>
</head>
<body>
<form name="form1">
<h1>Register Online</h1>
<Table>
<tr>
<td>First Name</td>
<td><input type="text" name="usrname" PlaceHolder="Enter your First Name" required></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="email" id="mail" PlaceHolder="Enter Your email address" pattern="[^@]+@[a-zA-z]+\.[a-zA-Z]{2,6}" required></td>
</tr>
<tr>
<td> Roll Number</td>
<td><input type="text id="roll"  PlaceHolder="Enter Your Roll Number" required></td>
</tr>
<tr>
<td>Training Program</td>
<td><select id="sel">
<option value="movie">select Training</option>
<option value="andro">Andro</option>
<option value="java">Java</option>
<option value="C">Robotics</option>
<option value="hack">ethical Hacking</option>
</select></td>
</tr>
<tr>
<td> Contact NUmber</td>
<td><input type="num" id="number" PlaceHolder="Enter Your Conatct Number" required></td>
</tr>
<tr><td>
<button type="submit">Submit</button></td>
<td><Button type="reset">Reset</button>
</td></tr>
</table>
</form>
</body>
</html>


open the mainframe.html file in google chrome.

NIIT Q2 ACTIVITY BOOK CHAPTER 8

Q2) You have been assigned a task to display the highest score of the game. This implies that even if the user closes the browser, the highest
    score should get stored locally and should be displayed when the user next time plays the game, as shown in the following figure.
    How will you perform this task?
    prerequisite: To inform this exercise, you need to use the solution of activity 6.2




// Create the canvas
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = 512;
canvas.height = 480;
document.body.appendChild(canvas)


//Background image
var bgReady = false;
varbgImage = new Image();
bgImage.onload = function(){
  bgReady = true;
};
bgImage.src = "image/background.png";


// Dave image
var daveready = false;
var daveImage = new Image();
daveImage.onLoad = function() {
    daveReady = true;
};
daveImage.src = "image/dave.png";


// Monster image
var monsterready = false;
var monsterImage = new Image();
monsterImage.Onload = function(){
   monsterReady = true;
};
monstreImage.src = "images/monster.png";


//game objects
var dave = {
    speed: 256// movement in pixels per second
};
var monster ={};
var monsterCaught = 0;
var timeleft = 30;

//Handle keyboard controls
var KeysDown={};
addEventListener("Keydown",function(e) {
     keysDown[e.keyCode] = true;
}, false);
addEventLitener("Keyup", function(e){
   delete keysDown[e.keyCode];
}, false);


// reset the game when the player catches a monster
var reset= function(){
    dave.x = canvas.width/2;
    dave.y = canvas.height/2;

// Throw the monster somwhere on the screen randomly
monster.x = 32+(Math.random() * (canvas.width -64));
monster.y = 32+(Math.random() * (canvas.height - 64));
};


// Update game objects
var update = function(modifier){
//if the time is not over
if(tmeleft>0)
{
  if(dave.y>0 && 38 in keysDown)
   {//player holding up
     dave.y -= dave.speed * modifier;
}
          else if(dave.y<=0 && 38 in keysDown)
          {
                timeleft=0;
                daveImage.src = "images/dead.png";
          }
      if(dave.y < 448 && 40 in keysDown) {// Player holding down dave.y += dave.speed * modifier;
         }
              else if(dave.y >= 448 && 40 in keyDown) { //Player Holding down timeLeft=0;
                          daveImage.src = "images/dead.png";
         }
         if(dave.x>0 && 37 in keysDown) {//player holding left
         dave.x -=dave.speed * modifier;
         }
           else if(dave.x<=0  && 37 in keysDown)
           {
               timeLeft=0;
daveImage.src = "images/dead.png";
}
if(dave.x<480 && 39 in keysDown)
           {
              timeLeft=0;
daveImage.src = "image/dead.png";
              }

          //Are they touching?
         if (
             dave.x <= (monster.x +32)
             && monster.x <= (dave.x + 32)
             && dave.y <= (monster.y + 32)
             && monster.y <= (dave.y + 32)
             ) {
                ++monsterCaught;
                reset();
                }
              }
              else
              {
                     //alert(localStorage.highestScore);
                     clearInterval(timesGamermain);
                     clearInterval(timerGame);
if (!localStorage.highestScore)
             localStorage.highestScore = 0;
             if (localStorage.highestScore < monsterscaught){
                localStorage.highestScore = monstersCaught;
                alert("Congratulations! You scored the highest!1");
                }
   
                     alert("game over\nYou have caught" + monstersCaught + "monsters in 30 seconds.");
                     }
 };


//Draw
var render = function(){
        if (bgready){
            ctx.drawImage(bgImage, 0, 0);
            }

            if(daveReady) {
               ctx.drawImage(daveImage, dave.x, dave.y);
            }
     
            if(monsterready) {
               ctx.drawimage(monsterImage, monster.x, monster.y);
            }
         
            //Score
            ctx.fillStyle = "rgb(250, 250, 250)";
            ctx.font = "24px Helevetica";
            ctx.textAlign = "left";
            ctx.textBaseline = "top";

    document.getElementById("dispscore").innerHTML="<font size=+2><b>highest Score:</b>"+
    localStorage.highestScore;

    document.getElementById("infoDiv").innerHTML="<font size=+2><b>MOnster Caught:</b>"+ monstersCaught +"
    <b>Time Left:</b>" + timeleft +"Sec</font>";

    };

    //The main game loops
     var main = function(){
          var now = date.now);
          var delta = now - then;
          update(delta/1000);
          render();
          then = now;
        };
//Time Restriction
var timeRestriction = function()
{
      timeLeft--;
}
//Let's play this game!
rese();
var then = date.now();
var timerGameMain=setInterval(main, 1);//Execute as fast as possible
var timergame=setInterval(timeRestriction,1000);




save the file and open the home.html file and type the code


<!Doctype html>
<html lang="en">
<head>
         <meta charset="utf-8">
         <title>Simple Canvas Game</title>
   </head>
</body>
<div id="infoDiv"></div>
<div id="dispScore"></div>
   
        <script src="game.js"></script>
</body>
</html>

NIIT HTML ACTIVITY BOOK CHAPTER 7

Chapter 7
 Q1)Create a link,Admission,on the SkyLight University website to display the admission calendar for the cources,Social Psychology,Botany,and Communications.The calendar appears when the user moves the mouse over the Admission Calendar link,as shown in the following figure.

<!DOCTYPE html>
<html>
<head>
<style>
a{color:orange;font-size:15px;}
th{color:red;font-size:15px;}
tr{color:red;font-size:15px;}
a{font-size:20px;color:blue;font-weight:bold;}
</style>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#coolMenu").hide();
$("#prooffers").hide();
$("#bank").mouseenter(function(){
$("#coolMenu").show(500);
});
$("#bank").mouseleave(function(){
$("#coolMenu").hide(500);
});
$("#pro").mouseenter(function(){
$("#prooffers").show(500);
});
$("#pro").mouseleave(function(){
$("#prooffers").hide(500);
});

});
</script>
</head>
<body><P>Place the mouse over the 'Admission Calender' link to view the admission calender (2013-14) for Social Psychology,Botany,and Communications.</P>
<a id-"bank" href-"">Admission Calender</a>

<div id="coolMenu" style="width:500px;height:200px;padding-top:0px;border:4px solid red;background-color:lightgrey;">
<table border="ipx solid red">
<tr>
<tr><td>1.</td><td>Social Psychology</td><td>Peter</td><td>07-04-2013</td><td>15-05-2013</td></tr>
<tr><td>2.</td><td>Botany</td><td>Mark.v.Wen</td><td>15-05-2013</td><td>30-05-2013</td></tr>
<tr><td>3.</td><td>Communications</td><td>Alice Ben</td><td>30-04-2013</td><td>10-05-2013</td></tr>
</table>
</div>
</body>
</html>


Q2)To enchanse the browsing experience of the users in the SkyLight University website,the management of the university wants the website should display the slideshow of the college campus images.When a user clicks the link,University Image Gallery,the slideshow starts,as shown in the following figure.

<HTML><HEAD><TITLE>SkyLight University</TITLE>
<link type="text/css" rel="stylesheet" href="ExternalStylesheet/homestylesheet.css"/>
<link media="screen"rel="stylesheet"href="gallery/css/colorbox.css"/>
<script src="gallery/jQueryS/jquery-1.8.3.js"></script>
<script src="gallery/jQueryS/jquery-colorbox.js"></script>
<script>
$(document).ready(function(){
$("a").colorbox({width:800,height:600,slideshow:true,current:false)};
});
</script>

<style>body{padding-left:50px;border:1px solid red;}</style></HEAD>
<BODY>
<h1>Our College Campus.....</h1><br>
<img src="images\campusimage1.png" width=210 height=160></img></a>
<img src="images\campusimage2.png" width=210 height=160></img></a>
<img src="images\campusimage3.jpg" width=210 height=160></img></a>
<img src="images\campusimage4.jpg" width=210 height=160></img></a>
<img src="images\campusimage5.jpg" width=210 height=160></img></a>
<article>
<P>The SkyLight University is a pioneer institute that distinctively contributes to the society in the field of research,learning and teacheing,and engagement.As a non-profit making organization,the University maintains its position among nation's top universities and is increasingly turning international in its outlook and reputation.</P>
<p>The Universityproposes academic programs in various streams,such as Arts,Commerce,IT,and Science.Students can opt for these programs through regular and distance education.Apart from studies,the University also aims at enchancing the overall personality of students,which enables them to grow.</p>
</article>
<details>
<summary><b>Colleges affliated:</b></summary><ul>
<li>
Denmeu College of Arts
<li>
Lebian College
<li>Armin College of Science
<li>LL College of Commerce
</details>
<BR>
<a href="gallery/contentfiles/Campusimage1.jpg" rel="collection"><b><i>University Image Gallery</i></b></a>
<a href="gallery/contentfiles/Campusimage2.jpg" rel="collection"></a>
<a href="gallery/contentfiles/Campusimage3.jpg" rel="collection"></a>
<a href="gallery/contentfiles/Campusimage4.jpg" rel="collection"></a>
<a href="gallery/contentfiles/Campusimage5.png" rel="collection"></a>
</body>
</html>


Q3)You have been assigned a task to create a Web page for the USASiteSeeing website.The Web page should dispaly the images of tourist locations is USA.In addition,you need to apply rollover effect on the images in such a way that the description of locations should appear on the image mouse over,as shown in the following figure.

<html>
<head>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<SCRIPT>
function over(img,imgsrc)
{
img.src=imagesrc;
}
function out(img,imgsrc)
{
img.src=imagesrc;
}
</SCRIPT>
<style type="text/css">

div.panelUSA{
width:410px;
height:120px;
display:none;
margin:0px;
padding:0px;
text-align:center;
background:FFCC66;
color:black;
border:solid 1px #c3c3c3;
}
</style>
</head>
<body bgcolor="beige">
<b><center><u><font face="Verdana" color="black" size="5">Travel</font><font face="Verdana" color="red" size="5"> Around.</font><font face="Verdana" color="black" size="5">Inc.</font></u></center></b>
<hr size="5" color="red">
<font face="Arial" color="#660033" size="4"><i>Welcome to our website<br/>There are many beautiful tourist locations to visit in USA.<br/>On this Website,you can get information about the tourist locations in USA.</i></font>
<table class="class1">
<tr>
<td colspan="5">
</td>
</tr>
<tr>
<td height="100" colspan="5"><font face="algerian" color="660033" size="6">USA</font></td>
</tr>
<tr><td colspan="8">
<div class="panelUSA">
<p><i>Some of the most prominent places to visit in USA are:</i><br/>Statue of Liberty,Central Park,Disneyland,Bellagio,South Beach,and many more...</p>
</div>
<p class="USA">Mouse over the image to view the information about the tourist locations</p></td></tr>
<td><IMG ID="Image1" src="nationalgallery.jpg" height="250" width="250" onmouseover="over(this,'NationalGOA_ex.png')" onmouseout="out(this,"nationalgallery.jpg')"/></td>
<td><IMG ID="Image2" src="sanjose.jpg" height="250" width="250" onmouseover="over(this,'sanjose_ex.png')" onmouseout="out(this,"sanjose.jpg')"/></td>
<td><IMG ID="Image3" src="statueofliberty.jpg" height="250" width="250" onmouseover="over(this,'StatueofLiberty_ex.png')" onmouseout="out(this,"statueofliberty.jpg')"/></td>
<td><IMG ID="Image4" src="WhitneyMuseumofAmericanArt.jpg" height="250" width="250" onmouseover="over(this,'Whitneymuseum_ex.jpg')" onmouseout="out(this,"WhitneyMuseumofAmericanArt.jpg')"/></td>
<tr>
</table>
</body>
</html>

NIIT HTML Q4 ACTIVITY BOOK CHAPTER 6

Q4) Advin is a web developer and has been assigned a task to rotate an image on canvas,
    as shown in the following figure.Help advin to perform this task.
    Prerequisite: To perform this exercise, you need to use the image file, car.gif.

Ans4)




<html>
<head>
<title></title>
<script type="text/javascript">
   var can, ctx, sprite,
       x, y, rot = 0;

       function init(){
          sprite = document.getElementById("Sprite");
          can = document.getElementById("canvas");
          ctx = can.getContext("2d");
          ctx.fillStyle = "blue";
          ctx.font = "12pt helvetica";
          ctx.textBaseline = "top";
          x = 100;
          y = 0;
          rot = 240;
          drawSprite();
          function drawSprite() {
          ctx.save();
          ctx.translate(x, y);
          ctx.rotate(rot);
          ctx.drawImage(sprite, 0, 0);
       
          ctx.restore();
          }
          </script>
          </head>
          <body onload="init()">
          <h2>Rotating Image</h2>
          <canvas id="canvas" height="800" width="800">
          </canvas>
          <img id="sprite" src="car.gif" style="display:none">
          </body>
          </html>
           

NIIT HTML Q3 ACTIVITY BOOK CHAPTER 6 Smiley face

Q3) You have been assigned a task to create a smiley on canvas. the face of the smiley
     should be colored in yellow, with eye balls colored in blue, and month outline in red, as shown in the following  figure. How will you perform this task?

Ans3)

<!Doctype HTML><html>
<head>
</head>
<body>
<canvas id="canvas" width='500' height="500"></canvas>
<script>
var ctc=document.getElementById("canvas");
var ctx=ctc.getContext("2d");
ctx.beginPath();
ctx.arc(150, 150, 100, 0, 2 * Math.PI, false);
ctx.closePath();
ctx.fillStyle="gold";
ctx.stroke();
ctx.fill();

ctx.beginPath();
ctx.arc(120, 130, 20, 0, 2 * Math.PI, false);
ctx.closePath();
ctx.fillStyle = "white";
ctx.stroke();
ctx.fill();


ctx.beginPath();
ctx.arc(123, 133, 4, 0, 2 * Math.PI, false);
ctx.closePath();
ctx.fillStyle="blue";
ctx.stroke();
ctx.fill();


ctx.beginPath();
ctx.arc(180, 130, 20, 0, 2 * Math.PI, false);
ctx.closePath();
ctx.fillStyle = "white";
ctx.stroke();
ctx.fill();


ctx.beginPath();
ctx.arc(183, 133, 4, 0, 2 * Math.PI, true);
ctx.closePath();
ctx.fillStyle = "blue";
ctx.stroke();
ctx.fill();

ctx.beginPath();
ctx.arc(155, 165, 60, 0, 3, false);
ctx.closePath();
ctx.lineWidth = 5;
ctx.strokeStyle = "red";
ctx.fillStyle = "white";
ctx.stroke();
ctx.fill();

</script>
</body>
</html>