Js tasks

 


1: Create a function that takes two numbers as parameters and returns their sum.

JS:
// Create a function that takes two numbers as parameters and returns their sum.
const button = document.querySelector("button");

function sum(one, two) {
    return one + two;
}

button.addEventListener("click", () => {
   
    let $i1 = document.querySelector("#i1").value;
    let $i2 = document.querySelector("#i2").value;

    let area = sum(Number($i1), Number($i2));
   
    console.log("Sum: ", area);

})

HTML:
<body class="mx-3">
    <section class="flex gap-10 pb-7">
        <div>
            <p>Input : 1</p><input id="i1" class="border-2" type="text" required>
        </div>
   
        <div>
            <p>Input : 2</p><input id="i2" class="border-2" type="text" required>
        </div>
    </section>

    <button class="border-2 px-2 border-red-600 text-red-800">Submit</button>

    <script src="index.js"></script>
</body>

 



2: Write a function that accepts a string and returns the length of that string.

JS:
// Write a function that accepts a string and returns the length of that string.

const button = document.querySelector("button");

function stringLength(x) {
    return x.length;
}

button.addEventListener("click", () => {

    const str1 = document.getElementById("i1").value;

    let answer = stringLength(str1);
    console.log(answer);

})

 




JS:


HTML:

 




JS:


HTML:




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 




JS:


HTML:

 



<b>JS:</b><div><br /><br /><b>HTML:</b></div><div><br /></div><div><p>&nbsp;</p><hr /><br /></div><div><b><br /></b></div>

Comments

Popular posts from this blog

Javascript whole in one

3: HTML blog's visual content with source code

Bootstrap whole in one