Ip Lab Mock and Final Exam Solution
Ip Lab Mock and Final Exam Solution
DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<form>
</form>
<span id = "result"></span>
</p>
</body>
</html>
function multiplyBy()
num1 = document.getElementById("firstNumber").value;
num2 = document.getElementById("secondNumber").value;
function divideBy()
num1 = document.getElementById("firstNumber").value;
num2 = document.getElementById("secondNumber").value;
useEffect(() => {
alert(`You clicked ${count} times`)
});
const handleUpdate = ()=> {
setCount (count + 1)
}
return (
<div>
<div>You have clicked {count} times</div>
<button onClick={ handleUpdate} >
Click me
</button>
</div>
);
}
export default App;
How to pass data from one component to other component in ReactJS ?
//Parent.js
import React from 'react'
import Child from './Child';
const Parent = () => {
const data = "Hello Everyone";
return(
<div>
<Child data={data}/>
</div>
);
}
export default Parent;
//Child.js
import React from 'react';
const Child = (props) => {
return(
<h2> {props.data} </h2>
);
}
export default Child;
//App.js
import React from 'react';
import "./index.css";
import Parent from './Parent'
const App = () => {
return (
<div className="App">
<Parent/>
</div>
);
}
export default App;
// check if number is 0
else if (number == 0) {
console.log("The number is zero");
}
let sum = 0;
const number = prompt('Enter a three-digit positive integer: ');
// if number is 0
if (x == 0) {
return 1;
}
// if number is positive
else {
return x * factorial(x - 1);
}
}
function greet() {
return 'Hello';
}
console.log(`${message} ${user}`);
}
name('John', greet);
name('Jack', greet);
name('Sara', greet);
Ref: https://www.programiz.com/javascript/examples
const fs = require('fs');
console.log(file_content);
console.log("Addition : "+calculator.add(a,b));
console.log("Subtraction : "+calculator.subtract(a,b));
console.log("Multiplication : "+calculator.multiply(a,b));
app.use('/', router);
app.listen(process.env.port || 3000);
Ref: https://codeforgeek.com/node-js-tutorial-step-by-step/
const FunctionalComponent=()=>{
const [count, setCount] = useState(0);
return (
<div style={{margin:'50px'}}>
<h1>Welcome to Geeks for Geeks </h1>
<h3>Counter App using Functional Component : </h3>
<h2>{count}</h2>
<button onClick={increase}>Add</button>
</div>
)
}
----------------------------------------------------------------
increase(){
this.setState({count : this.state.count +1});
}
render(){
return (
<div style={{margin:'50px'}}>
<h1>Welcome to Geeks for Geeks </h1>
<h3>Counter App using Class Component : </h3>
<h2> {this.state.count}</h2>
<button onClick={this.increase}> Add</button>
</div>
)
}
}
componentWillMount()
{
console.log("componentWillMount()");
}
componentDidMount()
{
console.log("componentDidMount()");
}
changeState()
{
this.setState({ hello : "Geek!" });
}
render()
{
return (
<div>
<h1>GeeksForGeeks.org, Hello{ this.state.hello
}</h1>
<h2>
<a onClick={this.changeState.bind(this)}>Press Here!
</a>
</h2>
</div>);
}
shouldComponentUpdate(nextProps, nextState)
{
console.log("shouldComponentUpdate()");
return true;
}
componentWillUpdate()
{
console.log("componentWillUpdate()");
}
componentDidUpdate()
{
console.log("componentDidUpdate()");
}
}
ReactDOM.render(
<Test />,
document.getElementById('root'));
greet() {
console.log(`Hello ${this.name}`);
}
}
// parent class
class Person {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hello ${this.name}`);
}
}
constructor(name) {
console.log(data.toString());
console.log("Program Ended");
console.log("Program Ended");
Now run the main.js to see the result −
$ node main.js
Verify the Output.
Program Ended
Tutorials Point is giving self learning content
to teach the world in simple and easy way!!!!!