javascript steps

// 2-now want to craet another table to but the data in it 

//but before we creat it we need a constructor function 

function data(from, to, capacity, reserve,lefted) {
this.from=from;
this.to=to;
this.capacity=capacity ;
this.reserve=reserve ;
this.lefted=0;
this.leftedSum=0

}


//now we can creat the table 
data.prototype.render=function()//Acsses the constructor function
{
 var tableEl = document.getElementById("table");

var trEl1=document.createElement('tr');
tableEl.appendChild(trEl1);

var tdEl1 = document.createElement('td');
trEl1.appendChild(tdEl1);
tdEl1.textContent=`${this.from}`


var tdEl2 = document.createElement('td');
trEl1.appendChild(tdEl2);
tdEl2.textContent=`${this.to}`



var tdEl3 = document.createElement('td');
trEl1.appendChild(tdEl3);
tdEl3.textContent=`${this.capacity}`



var tdEl4 = document.createElement('td');
trEl1.appendChild(tdEl4);
tdEl4.textContent=`${this.reserve}`


var tdEl5 = document.createElement('td');
trEl1.appendChild(tdEl5);
tdEl5.textContent=`${this.lefted}`

}

//call the function 
data.prototype.render();


3.88
7
MacK 80 points

                                    //define the html form in JS
var formEl = document.getElementById("form");
var allData=[];

3.88 (8 Votes)
0
4
7
Nunro 70 points

                                    //want to link the form inputs with the submit 

// add event listner 

formEl.addEventListener("submit",click);

function click(event){
    event.preventDefault();
 var from = event.target.from.value;
 var to = event.target.to.value;
 var capacity = event.target.capacity.value;
 var reserve = event.target.reserve.value;
 var object=new data(from,to,capacity,reserve);
 object.leftedSeats();
 object.render();
 object.total();
 set();

}

4 (7 Votes)
0
4.17
6

                                    // want to creat a table 

//1- start with the header
var tableEl = document.getElementById("table");//Global variable we can use it without declare it again 
var headerArr=['from','to','capacity','reserve','lefted'];
function header(){
  var trEl = document.createElement('tr');
  tableEl.appendChild(trEl);
  for(var i=0 ; i < headerArr.length ; i++ ){
var thEl = document.createElement('th');
trEl.appendChild(thEl); 
thEl.textContent = `${headerArr[i]}`;
}
}
//call the function
header();

4.17 (6 Votes)
0
4.2
10
Andrestand 65 points

                                    
// now I want to calculate the lefted seats 

data.prototype.leftedSeats=function() //Acsses the constructor
{
    
    this.lefted = this.capacity-this.reserve ;

}

data.prototype.leftedSeats();

4.2 (10 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source