Challenge unlock for my Student!

Given two numbers, return true if the sum of both numbers is less than 100. Otherwise return false .

Examples

lessThan100(22, 15) ➞ true
// 22 + 15 = 37

lessThan100(83, 34) ➞ false
// 83 + 34 = 117

lessThan100(3, 77) ➞ true
1 Like

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width= initial-scale=1.0">
  <title>Document</title>
</head>

<body></body>
    <script>
   var lessThan100=(a,b)=>{
    if(a+b<100){
      return true;
    }
    else return false;
   }
   console.log(lessThan100(22,15));
   console.log(lessThan100(83,34))
   console.log(lessThan100(3,77))
    </script>

</body>

</html>

2 Likes
function lessThan100(x,y){
  
    if(x+y < 100){
       document.write(true)
    }
    else if(x+y>100){
        document.write(false)
    }
    
}
lessThan100(22, 15)
lessThan100(83, 34)
lessThan100(3, 77)
1 Like

var num1=Number(prompt(“Enter a num”));
var num2 =Number(prompt(“Enter second num”));
var sum=num1+num2;
// document.write(sum)
if(sum<=100){
document.write(“True”)
}
else if(sum>=100){
document.write(“false”)
}

2 Likes

Create a function that takes the age in years and returns the age in days.

Examples

calcAge(65) ➞ 23725

calcAge(0) ➞ 0

calcAge(20) ➞ 7300

Notes

  • Use 365 days as the length of a year for this challenge.
  • Ignore leap years and days between last birthday and now.
  • Expect only positive integer inputs.

Answer-1:

<!DOCTYPE html>
<html>
<head>
  <title>True or False</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      text-align: center;
    }

    .container {
      margin-top: 50px;
    }

    button {
      padding: 10px 20px;
      font-size: 16px;
      background-color: #3498db;
      color: #fff;
      border: none;
      cursor: pointer;
      border-radius: 5px;
    }

    button:hover {
      background-color: #2980b9;
    }

    p {
      font-size: 18px;
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <div class="container">
    <h2>Check if the Sum is Less Than 100</h2>
    <label for="num1">Enter first number:</label>
    <input type="number" id="num1" required>
    <br>
    <label for="num2">Enter second number:</label>
    <input type="number" id="num2" required>
    <br>
    <button onclick="checkSum()">Check Sum</button>
    <p id="result"></p>
  </div>

  <script>
    const checkSum = () => {
      const num1 = parseInt(document.getElementById("num1").value);
      const num2 = parseInt(document.getElementById("num2").value);
      const sum = num1 + num2;
      const resultElement = document.getElementById("result");

      const message = sum < 100
        ? `True: ${num1} + ${num2} = ${sum}`
        : `False: ${num1} + ${num2} = ${sum}`;

      resultElement.textContent = message;
    };
  </script>
</body>
</html>

2 Likes

  let calAge=(age)=>{
    return age*365;
  }
  console.log(calAge(65));
  console.log(calAge(0));
  console.log(calAge(20));

1 Like
var calcAge =(age)=>{

return age * 365

}

console.log(calcAge(65))

console.log(calcAge(0))

console.log(calcAge(20))
1 Like
<!DOCTYPE html>
<html>
<head>
  <title>Age Calculator</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      text-align: center;
      margin-top: 100px;
    }

    .container {
      width: 300px;
      margin: 0 auto;
      padding: 20px;
      border: 1px solid #ccc;
      border-radius: 5px;
    }

    input[type="number"] {
      width: 100%;
      padding: 10px;
      font-size: 16px;
      margin-bottom: 10px;
    }

    button {
      width: 100%;
      padding: 10px;
      font-size: 16px;
      background-color: #3498db;
      color: #fff;
      border: none;
      cursor: pointer;
      border-radius: 5px;
    }

    button:hover {
      background-color: #2980b9;
    }

    p {
      font-size: 18px;
      margin-top: 20px;
    }

    .error {
      color: #ff0000;
      font-size: 14px;
    }
  </style>
</head>
<body>
  <div class="container">
    <h2>Age Calculator</h2>
    <label for="age">Enter your age in years:</label>
    <input type="number" id="age" required>
    <button onclick="calculateAge()">Calculate Age in Days</button>
    <p id="result"></p>
    <p id="error-msg" class="error" style="display: none;">Please enter a positive integer.</p>
  </div>

  <script>
    const calculateAge = () => {
      const ageInYears = parseInt(document.getElementById("age").value);

      if (isNaN(ageInYears) || ageInYears <= 0) {
        document.getElementById("error-msg").style.display = "block";
        document.getElementById("result").textContent = "";
      } else {
        document.getElementById("error-msg").style.display = "none";
        const ageInDays = ageInYears * 365;
        document.getElementById("result").textContent = `Your age in days is: ${ageInDays}`;
      }
    };
  </script>
</body>
</html>

2 Likes

var a =Number(prompt(“enter a num1”));
var b = Number(prompt(“enter a num2”));
// document.write(a+b);
if(a+b < 100){
document.write(true);
}
else{
document.write(false);
}

1 Like