32
loading...
This website collects cookies to deliver better user experience
More Functions of a Transpilers.
Have u ever heard of the language like Typescript or any other language that is used in place of JavaScript.
These language also uses the Transpilers to convert their code into Valid javaScript Code.
The point of using these languages that they are more easy to learn in referance to the JavaScript.
<div>
<h3>JSX Demo</h3>
<img src="image.src"/>
</div>
React.createElement(
"div", null,
React.createElement("h3", null, "JSX Demo"),
React.createElement("img", { src: "image.jpg})
);
//You can also write this javaScript code instead of the JSX the program will work the
same way.
{}
.class Demo extends React.Component{
render(){
return <h3>Your Marks are : {12*6}</h3>;
}
}
{}
.//Mood Representer
function getName(){
const names = ["Rajiv","Sanjay","Michel","Harry","Honey","Jayant"];
return names[Math.floor(Math.random()*names.length)];
}
function getMood(){
const Moods= ["😇","😀","😄","😁","😆","😅","😂","🤣","😊","😇","😍"];
return Moods[Math.floor(Math.random()*Moods.length)];
}
class Moods extends React.Component{
render(){
return (<h3>{getName()} mood is : {getMood()}</h3>)
}
}
class App extends React.Component{
render(){
return(
<div>
<Moods/>
<Moods/>
<Moods/>
</div>
)
}
}
ReactDOM.render(<App/>,document.getElementById('root'));
if else
⇒
//Magic Number
function getNum() {
return Math.floor(Math.random() * 10 + 1);
}
// Using if and else
class MagicNum extends React.Component{
render(){
const num = getNum();
let msg;
if(num===7){
msg = "Congrates!!!!"
}
else{
msg = "Better luck next Time";
}
return (
<div>
<h1>Your Number is : {num}</h1>
{msg}
</div>
);
}
}
//Using Ternary Operator
class MagicNum extends React.Component {
render() {
const num = getNum();
return (
<div>
<h1>Your Number is : {num}</h1>
<p>{num===7? "Congrats!!!" : "Better luck next time" }</p>
</div>
);
}
}
//Using & opeartor
class MagicNum extends React.Component {
render() {
const num = getNum();
return (
<div>
<h1>Your Number is : {num}</h1>
<p>{num === 7 ? "Congrats!!!" : "Better luck next time"}</p>
{num === 7 && (
<img src="https://images.unsplash.com/photo-1641005361416-fba29d009bd2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyM3x8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=60" />
)}
</div>
);
}
}
ReactDOM.render(<MagicNum />, document.getElementById("root"));