Back to feed
Renewal·서른의 생활코딩

Sample Source 1) JavaScript Basics (if and if-else Statements)

NS
normalstory
cover image



if statement

Example 5)



<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">

<head>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />

<title> IF statement </title>

<meta name="Keywords" content="" />

<meta name="Description" content="" />

</head>

<body>


<p>test"1"</p>

<p>test2</p>


<script type="text/javascript">

//<!CDATA[

var reply=confirm("I will study hard");

if(reply==true){

alert("Yes study hard");

}

//]]]]>

</script>


</body>

</html>





 if-else statement 

Example 6)


Basic condition


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">




<head>


<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />


<title> IF-else statement </title>


<meta name="Keywords" content="" />


<meta name="Description" content="" />


</head>


<body>




<script type="text/javascript">


//<!CDATA[


var age=20;




if(age>=20){


alert("Entry allowed");


}else{


alert("Entry denied");


}


//]]]]>


</script>




</body>


</html>



Add conditions


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">




<head>


<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />


<title> IF else 문 </title>


<meta name="Keywords" content="" />


<meta name="Description" content="" />


</head>




<body>


<script type="text/javascript">


//<!CDATA[


var age=17;


var sex="men";


/*
Conditions: ages 17~19, only males allowed


var reply1=confirm("Are you 17~19?");


var reply2=confirm("Are you male?");




if(reply1==true){


if(reply2==true);


alert("Please enter.");


}else{


alert("Entry denied.");


}


*/


if((age>=17&&age<=19)&&sex=="men"){


alert("Pass.");


}else{


alert("Fail.");


}


//]]]]>


</script>


</body>




</html>



Add conditions 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">




<head>


<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />


<title> Conditional 3 </title>


<meta name="Keywords" content="" />


<meta name="Description" content="" />


</head>


<body>




<script type="text/javascript">


//<!CDATA[


var name=prompt("Enter your name","");


document.write(name);


/*


if(name==null){


alert(name+", nice to meet you..");


}else{


alert("I told you to enter your name");


}


*/


if(name==""){


alert("I told you to enter your name");


}else{


alert(name+", nice to meet you..");


}


//]]]]>


</script>




</body>


</html>



Applied conditions


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">




<head>


<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />


<title> Conditional 4 </title>


<meta name="Keywords" content="" />


<meta name="Description" content="" />


</head>


<body>




<script type="text/javascript">


//<!CDATA[


var number=prompt("Enter a number you like","");


document.write(number);




if(number%2==0){


alert("It is even.");


}else{


alert("It is odd.");


}


//]]]]>


</script>




</body>


</html>

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Steadily, for the long haul, without burning out

Mar 31, 2026·9 min
Renewal

Tech-life balance

Feb 7, 2026·3 min
Renewal

Humanality, by Park Jeong-ryeol

Feb 7, 2026·11 min