Home > Mobile >  js function stops acting
js function stops acting

Time:09-28

![Text](https://stackoverfl

var obj = {
    count: 1
}
function elementSet()
{
if(obj.count=1){
    document.getElementById("text").textContent = "graa";}
if(obj.count=2){
    document.getElementById("text").textContent = "graa";}
if(obj.count=3){
    document.getElementById("text").textContent = "graa";}
}

function back()
{
    
    if(obj.count>1)
    {   
        
        obj.count = obj.count -1;
        document.getElementById("back").style.display = "block";
        document.getElementById("page_num").textContent = obj.count;     
    }
    
    
}
function forth()
{
    
    if(obj.count<3){
    obj.count = obj.count  1;
    document.getElementById("page_num").textContent = obj.count;
     document.getElementById("forth").style.display = "block";   
          if (obj.count>3){
     document.getElementById("forth").style.display = "none";}
     
    }
    
}
.colx1 {
    color: #e1992e;
    /* height: 3px; */
    font-size: 2.1ch;
    margin-right: 80%;
    inline-size: auto;
    border-color: #e1992e;
    border-radius: 11ch;
}
.colx2 {
    color: #e1992e;
    font-size: 2.1ch;
    inline-size: auto;
    margin-top: -3%;
    margin-left: 80%;
    border-color: #e1992e;
    border-radius: 11ch;
}
.colabount 
{
    width: 170px;
}
.row {
    display: inline;
    
}
.body
{
    text-align: center;
    max-height: 100%;
}
.button {
    border-color: #e1992e;
}
.page_num
{
    color: black;
    size: 13ch;
    text-align: center;
}
.text 
{
    color: blanchedalmond;
    size: 12ch;
    
}
<!DOCTYPE html>
<html>

<head>
    
    <title>films</title>
    <link rel="stylesheet"
          href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> 
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
    

</head>

<body  >
    <div  id="content">
    
        <h2 id="text"  type="textContent"> its the f</h2> 
        <div >
            <button  id="back" type="button" onclick="back(),elementSet()"><b>back</d></button>
                
            <button   id="forth" type="button" onclick="forth(),elementSet()"><b>forth</d></button>
        </div>
        <div ><b id ="page_num">1</b></div>
    </div>
</body>

</html>

ow.com/image.jpg)

i tried to create external obj that contain count its working.
the page content will change acording to the count number.
the proble starts when im calling 'elementSet' = {checking abount obj.count and
changing the page acordingly}

THE PROBLEM : when elementSet runs back() and forth() not working anymore!

CodePudding user response:

your mistake is that:
in java script = is assignment. for example: let a = 0; we assignment 0 to a. now a is 0.
and we have == and ===. these are use for comparison in logics and Condition. for example:\

let a = 0;
a == 0 && console.log("yes");

there are some different between == and ===. you can read that in a link!

  • Related