I have looked online and tried myself ... but i have confused my self and nothing seems to be working. Can anyone help me to save and count many repeating 7s in one integer from prompt input.
var countNum = prompt("Enter an integer ", "Type here ");
document.getElementById("integer").innerHTML = countNum;
答案 0 :(得分:0)
可能会帮助你
var countNum = prompt("Enter an integer ", "Type here ");
document.getElementById("integer").innerHTML = countNum.split('7').length - 1;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<div id="integer"></div>
</body>
</html>
答案 1 :(得分:0)
您可以使用regular expression:
FOSRestBundle
&#13;
var countNum = prompt('Enter an integer', 'Type here'),
divInteger = document.getElementById('integer');
divInteger.innerHTML = (countNum.match(/7/g) || []).length;
&#13;